require "Common/define"
require "Logic/Config"
require "Common/functions"
require "Net/RankBattleHandler"
require "Battle/Editor/SkillRoleMgr"
require "proto/dungeon/bean/DungeonFormtaion"

local TopPanel = require "View/BattleUI/UIBattleTopChapterPanel"
---@type BattleTeamDarkStreetPanel
local BattleTeamDarkStreetPanel = require("View/BattleUI/BattleTeam/BattleTeamDarkStreetPanel")
local type = type
--- 支援队友站位
local SUPPORT_TEAMMATE_SITE = 6

UIBattleTeam = UIBase.New(PanelNames.UIBattleTeam)
local fightType = nil
local param = nil
local battleAct = nil
local backAct = nil
local currentFightType = -1
local nodeCount = 5
local mapName = ""
local m_team_list --预设编队列表
local m_choose_team --当前选择的编队
local m_current_show_skill = 0 --当前显示的支援技
local m_record_force_list = {} --记录被强制更换队伍的英雄id

--fightType 战斗类型
--param  参数 （用来处理特殊要求,比如竞技场 进攻/防守 和对手阵容）
--battleAct  必填
--backAct 可空
function UIBattleTeam.Init(_fightType, _param, _battleAct, _backAct)
    --AudioManager.PlayByEventName("Set_SubMenu_Battle_State_None",nil,AudioManager.WwiseFlagEnum.Music)
    fightType = _fightType
    param = _param;
    battleAct = _battleAct;
    backAct = _backAct;
    BattlePlaybackManager.SetFightType(_fightType)
    if type(_param) == "table" then
        BattlePlaybackManager.SetFormationType(_param and _param.type)
    else
        BattlePlaybackManager.SetFormationType(nil)
    end

    UIBattleTeam.fairyBatching = false
    UIBase.Init(UIBattleTeam)

end

function getPartnerById(id)
    for i = 1, #self.tableHeros do
        if self.tableHeros[i].partnerId == id then
            return self.tableHeros[i]
        end
    end
end

function UIBattleTeam:OnCreate(obj)
    self:RegisterEvent(Config.EventType.RefreshFormationList, function()
        m_team_list = FormationManager.GetAllFormation()
        self.Teamlist.numItems = logicMgr.FormationManager.GetMax()
        closeUI(PanelNames.UIBattleTeamEditor)
    end)
    self:RegisterEvent(Config.EventType.FormationSetFinish, function()
        m_team_list = FormationManager.GetAllFormation()
        self.Teamlist.numItems = logicMgr.FormationManager.GetMax()
        UISysTips.AddMsg(getLanguage("UIBattleManyTeams1011"))
        closeUI(PanelNames.UIBattleTeamEditor)
    end)

    self.isInit = true
    self._restrainTime = 2000 -- 对位克制箭头消失时间(毫秒)
    self.powerEnemyNum = 0
    self.formationType = nil
    self.tabBtnHeroType = {}
    self.dynamicList = nil
    self.btnBack = nil
    self.btnBoss = nil
    self.resetHeroBtn = nil
    self.teamController = nil
    self.tableFormationIndex = {}--编队按钮
    self.isShowTitle = false
    self.isShowDebris = false--显示碎片

    self.petShowCfg = {}

    self.curTabType = nil
    self.tabHeroItem = {}
    self.isNeedOpenHeadMenu = false
    self.tabHeroPosItem = {}
    self.selectedDrag = nil
    self.startPos = nil
    self.dragPos = nil
    self.tileWidth = 100
    self.tileHeight = 200
    self.curHeroData = nil
    self.tabHeroPosDataTemp = {}
    self.tabHeroPosDataTemp2 = {}
    self.tabHeroPosData = {}
    self.lastFormationPosData = {}--上一次刷新阵容时的阵容
    self.tabMonsterPosData = {}
    self.helpMan = {};
    self.helpManId = {};
    self.lastHelpManId = nil;
    self.enemyHelpMan = {}
    self.enemyHelpManId = { 0, 0, 0 }
    self.tabOwner = {}
    self.tableHeros = {} -- 可选的英雄列表
    self.tableLeaseHeros = {}; -- 主线租借英雄
    self.tabLeaseHero = {};
    self.tableCount = 0; -- 租借英雄数量
    self.tabLeaseAndOwnerHeros = {};  -- 租借和自己英雄ItemGo key: modelId;
    self.tabLeaseAndOwnerHeroIndex = {}; -- 租借和自己英雄位置
    self.formations = {} -- 阵容列表 key:阵容索引 value:id数组
    self.oppoFormations = {} -- 敌方阵容列表 key:阵容索引 value：partnerId,parnterMdoelId,level,star
    self.formationsIndex = nil --当前设置的第几阵容
    self.formationsMax = 1 --本次阵容设置数量
    self.battleBossFunction = nil --点击战斗的回调函数 参数：self.formations 无返回值
    self.backFunction = nil -- 返回的回调函数 无参无返回值
    self.checkFunction = nil -- 阵容设置结束后判断是否可以通过 参数：阵容列表 返回bool
    self.Count = 0
    self.oderLayer = nil
    self.enemyIndex = { 1, 3, 2, 4, 5 }
    self._counterpointList = { 1, 2, 1, 2, 2 } -- 对位关系
    self.restrainObjList = { {}, {} }
    self.playRestrainTimeList = { {}, {} }
    self.stageConfig = nil
    self.curFightType = nil
    self.leftPos = {}
    self.leftIndex = {}
    self.leftRole = {}
    self.rightPos = {}
    self.leftRect = {}
    self.leftRectPos = {}
    self.occupationBtns = {}
    self.occupationItems = {}--职业图片
    self.occupationEnemyItems = {}--敌人职业图片
    self.heroRectItems = {}
    self.battleInfo = {}
    self.battleInfo.myHelpManId = {}
    self.battleInfo.enemyHelpManId = {}
    self.battleInfo.helpSkillId = 0
    self.clickIndex = 0
    self.isFriendBattle = nil
    self.playerIds = {}
    self.btnShowDec = nil

    self.leftBottoms = {}
    self.rightBottoms = {}
    self.allHpText = nil
    self.allAttackText = nil
    self.tipsText = nil--提示信息
    self.effectList = {}
    self.effectTimers = {}
    self.isMove = false;
    self.btnChapterReward = nil;
    self.btnChapterRewardTips = nil;
    self.btnChapterRewardIcon = nil;
    self.combinationList = nil;--羁绊技能列表
    self.combinationListEnemy = nil;--敌人羁绊列表
    self.combinationListEnemyBgCtrl = nil;--敌人羁绊列表背景
    self.combinationListBgCtrl = nil;--我方羁绊列表背景
    self.combinationCom = nil;--羁绊技能
    self.btnCombinationComClose = nil;--关闭羁绊界面
    self.combinationComCtrl = nil;--显示羁绊技能
    self.combinationListInfo = {};--羁绊技能数据
    self.combinationListInfoEnemy = {};--敌人羁绊技能数据

    self.btnSkip = nil;--是否开启战斗跳过的按钮
    self.showBtnSkipCtrl = nil;--是否显示开启战斗跳过按钮控制器 1 显示 0 不显示

    self.upBattleShowComBack = nil;--神魔上阵特效后层
    self.upBattleShowComFore = nil;--神魔上阵特效前层
    self.upBattleShowItemBack = {};--神魔上阵特效后层节点集合
    self.upBattleShowItemFore = {};--神魔上阵特效前层节点集合
    self.upBattleEffectForeAni = {};
    self.upBattleEffectBackAni = {};
    self.upBattleEffectForeObj = {};
    self.upBattleEffectBackObj = {};
    self.upBattleEffectForeDrawWrapper = {};
    self.upBattleEffectBackDrawWrapper = {};

    for i = 1, 6 do
        local item = self:GetChild("occupation_" .. i)
        table.insert(self.occupationBtns, item)
    end
    for i = 1, 8 do
        local role = self:GetChild("leftRect" .. i)
        table.insert(self.leftRect, role)
    end
    for i = 1, 8 do
        local role = self:GetChild("left" .. i);
        role.displayObject.gameObject.name = "left" .. i
        role.draggable = true;
        role.onTouchBegin:Add(function()
            self.isMove = true;
            self:onDragStartFunc(role)
        end);
        role.onTouchMove:Add(function()
            self:onDragMoveFunc(role)
        end);
        role.onTouchEnd:Add(function()
            self:onDragEndFunc(role)
            self.isMove = false;

        end);
        table.insert(self.leftRole, role);
        role.onClick:Add(function()
            if self.clearController.selectedIndex == 1 then
                return
            end
            if i >= nodeCount + 1 then
                if fightType == EnumConst.FightTypeConst.RankBattle and logicMgr.RankBattleManager.BanPick() then
                    if logicMgr.RankBattleManager.LastIsChoose(self.helpMan[self.formationsIndex].partnerModelId) then
                        return
                    end
                end
                if self.playerIds[i] and int64ToNumber(self.playerIds[i]) ~= 0 then
                    self:BorrowInfo(self.helpMan[self.formationsIndex])
                else
                    if self.helpMan[self.formationsIndex] then
                        self:onClickHero(self.helpMan[self.formationsIndex], self.tabHeroItem[tostring(self.helpManId[self.formationsIndex])]);
                    end
                end
            else
                if fightType == EnumConst.FightTypeConst.RankBattle and logicMgr.RankBattleManager.BanPick() then
                    if logicMgr.RankBattleManager.LastIsChoose(self.tabHeroPosData[i].partnerModelId) then
                        return
                    end
                end
                if self.tabHeroPosData[i]["partnerId"] ~= nil then
                    if self.playerIds[i] and int64ToNumber(self.playerIds[i]) ~= 0 then
                        self:BorrowInfo(self.tabHeroPosData[i])
                    else
                        self:onClickHero(self.tabHeroPosData[i], self.tabHeroItem[self.tabHeroPosData[i]["partnerId"]])
                    end
                end
            end
        end)
        table.insert(self.leftIndex, role.parent:GetChildIndex(role))
    end
    for i = 1, 8 do
        local role = self:GetChild("right" .. i)
        role.displayObject.gameObject.name = "right" .. i
        table.insert(self.rightPos, role)
    end
    for i = 1, 8 do
        local leftBottom = self:GetChild("Loader_Left" .. i)
        local rightBottom = self:GetChild("Loader_Right" .. i)

        table.insert(self.leftBottoms, leftBottom)
        table.insert(self.rightBottoms, rightBottom)
    end
    for i = 1, #self._counterpointList do
        table.insert(self.restrainObjList[1], self:GetChild("myteam" .. i))
        table.insert(self.restrainObjList[2], self:GetChild("enemyteam" .. i))
    end

    self.leftGroup = self:GetChild("groupLeft")
    self.btnController = self:GetController("btnController")
    self.power = self:GetChild("power")
    self.bg = self:GetChild("bg")
    self.powerEnemy = self:GetChild("powerEnemy")
    self.helpSkill = self:GetChild("Icon")
    self.enemyHelpSkill = self:GetChild("Icon2")
    self.supSkillLeftBtn = self:GetChild("LeftSup")
    self.petSkill = self:GetChild("PetSup")
    self.Btn_HeroTactics = self:GetChild("Btn_HeroTactics")
    self.petRightSkill = self:GetChild("PetSupenemy")
    self.skillRedDots = self:GetChild("SkillRedDots")
    local Com_EnemySup = self:GetChild("Com_EnemySup")
    self.supSkillRight = Com_EnemySup:GetChild("RightSup")
    self.dynamicList = self:GetChild("headList")
    self.btnBack = self:GetChild("BtnBack")
    self.btnBoss = self:GetChild("BtnBoss")
    self.btnManual = self:GetChild("Manual")
    self.btnQuickChange = self:GetChild("btn_quickchange");
    self.resetHeroBtn = self:GetChild("n50")
    self.teamController = self:GetController("team")
    self.btnShowDec = self:GetChild("showDec")
    self.text_clearRequist = self:GetChild("text_clearRequist")
    self.btnShowDebris = self:GetChild("showDebris")    --奇异碎片
    self.btnPetShow = self:GetChild("showInfo")
    self.ctrlIfMainBattle = self:GetController("ifMainBattle")
    self.friendCtrl = self:GetController("friendctrl")
    self.myWinTimerText = self:GetChild("winMy")
    self.otherWinTimerText = self:GetChild("winOther")
    self.competeBattleWinsCtrl = self:GetController("CompeteBattleWins")
    --self.bgCtrl = self:GetController("BgFront")
    self.supCtrl = self:GetController("Sup")
    self.tipsText = self:GetChild("Text_ClickHeroTips")
    self.ctrlNumTeams = self:GetController("NumTeams")
    self.clearController = self:GetController("Clear")
    self.heroTacticsController = self:GetController("HeroTactics")

    self.ctr_teamShow = self:GetController("TeamShow")
    self.ctr_teamListShow = self:GetController("TeamListShow")
    self.btn_close = self:GetChild("btnClose")
    self.btn_bgclose = self:GetChild("bgclose")
    self.ctr_teamIsNil = self:GetController("TeamListNull")

    self.btn_teamEditor = self:GetChild("ButtonTeam")
    self.Teamlist = self:GetChild("Teamlist")
    self.BtnGo = self:GetChild("BtnGo")
    self.Teamlist.itemRenderer = function(index, obj)
        self:TeamEditorRenderer(index, obj)
    end
    self.btnSkip = self:GetChild("btnskip");
    self.showBtnSkipCtrl = self:GetController("showBtnSkip");
    self.showBtnSkipCtrl.selectedIndex = 0;
    --self.Text_NextDarkStreet = self:GetChild("Text_NextDarkStreet")
    -- self.Text_DarkStreetChallenge = self:GetChild("Text_DarkStreetChallenge")
    -- self.Btn_Add = self:GetChild("Btn_Add")
    self.showHeroEffects = { {}, {} }
    for i = 1, 8 do
        local itemLeft = self:GetChild("Effect_Left" .. i)
        local itemRight = self:GetChild("Effect_Right" .. i)
        table.insert(self.showHeroEffects[1], itemLeft)
        table.insert(self.showHeroEffects[2], itemRight)

    end
    for i = 1, 5 do
        local btn = self:GetChild("team" .. i)
        btn.visible = false;
        table.insert(self.tableFormationIndex, btn)
    end

    self.btnChapterReward = self:GetChild("btnChapterReward");
    self.btnChapterRewardTips = self.btnChapterReward:GetChild("tips");
    self.btnChapterRewardIcon = self.btnChapterReward:GetChild("icon");
    local btnChapterRewardTitle = self.btnChapterReward:GetChild("title");
    btnChapterRewardTitle.text = getLanguage("ChapterRewardText2");

    self:addEvent();
    if not self.topChapterPanel then
        self.topChapterPanel = TopPanel.New()
        self.topChapterPanel:OnCreate(self:GetChild("txtCom"))
        self.topChapterPanel:InitMiniMap(self:GetChild("MapBtn"))
    end
    self.darkStreetPanel = BattleTeamDarkStreetPanel.New()
    local Com_Now = self:GetChild("Com_Now")
    local Com_Next = self:GetChild("Com_Next")
    local Text_RewardLimit = self:GetChild("Text_RewardLimit")
    local Text_RewardLimit2 = self:GetChild("Text_RewardLimit2")
    local ctrlDarkStreetNext = self:GetController("DarkStreet")
    self.darkStreetPanel:OnCreate(Com_Now, Com_Next, Text_RewardLimit, Text_RewardLimit2, ctrlDarkStreetNext)
    self.combinationCom = self:GetChild("HeroComb");
    self.btnCombinationComClose = self:GetChild("n622");
    self.combinationList = self:GetChild("CombinationList");
    self.combinationList.itemRenderer = function(idx, obj)
        self:rendererCombinationSkillItem(idx, obj, self.combinationListInfo, 0);
    end
    self.combinationListBgCtrl = self:GetController("Combination");--敌人羁绊列表
    self.combinationListEnemyBgCtrl = self:GetController("CombinationEnemy");--敌人羁绊列表背景
    self.combinationListEnemy = self:GetChild("CombinationList_Enemy");
    self.combinationListEnemy.itemRenderer = function(idx, obj)
        self:rendererCombinationSkillItem(idx, obj, self.combinationListInfoEnemy, 1);
    end
    self.combinationComCtrl = self:GetController("showComb");
    self.mapHolder = self:GetChild("Graph_AutoFightMap");
    --self.bgShowCtrl = self:GetController("BgShow");
    --self.bgShowCtrl.selectedIndex = 1
    self:SetBgType()
    --self:RefreshDarkStreetTime()
    --self:RefreshDarkStreetChallengeTimes()
    self.mainReward = self:GetChild("mainReward")
    logicMgr.FuncOpenManager.refreshMainReward(self.mainReward, Config.FuncOpenType.DarkStreet)

    --self.upBattleShowComFore = self:GetChild("Graph_buzhen_fore");--神魔上阵特效前层
    --self.upBattleShowComBack = self:GetChild("Graph_buzhen_back");--神魔上阵特效后层
    for i = 1, 2 do
        self.upBattleShowItemBack[i] = {};
        self.upBattleShowItemFore[i] = {};
        for j = 1, 6 do
            local itemShowFore = self:GetChild("Graph_buzhen_fore" .. i .. j);
            local itemShowBack = self:GetChild("Graph_buzhen_back" .. i .. j)
            local posTarget = itemShowBack;
            --itemShowBack:SetPosition(posTarget.x, posTarget.y, 0);
            itemShowFore:SetPosition(posTarget.x + 15, posTarget.y, 0);

            table.insert(self.upBattleShowItemBack[i], itemShowBack);
            table.insert(self.upBattleShowItemFore[i], itemShowFore);
        end
    end
    self.starObj = {}
    for i = 1, 3 do
        self.starObj[i] = {}
        self.starObj[i]["ctrl"] = self:GetController("Star0" .. i)
        self.starObj[i]["desc"] = self:GetChild("text_0" .. i)
    end
    self.mythicShow = self:GetController("MythicStar")
    BattlePlaybackManager.isWaiting = false
    self:RefreshTeamEditor()
end

function UIBattleTeam:TeamEditorRenderer(index, obj)
    local ctr_mask = obj:GetController("mask")
    local ctr_choose = obj:GetController("ischoose")
    local ctr_buttonUse = obj:GetController("ButtonUse")
    local heros = obj:GetChild("list_herohead")
    local tips = obj:GetChild("tips")
    local btn_use = obj:GetChild("btn_QuickGet")
    local btn_supskill = obj:GetChild("btnSupSkill")
    local img_supskill = btn_supskill:GetChild("icon"):GetChild("icon")
    local btn_bg = obj:GetChild("btn_bg")
    local ctr_btnlist = obj:GetController("ButtonList")
    local btn_rename = obj:GetChild("ButtonTips1")
    local btn_top = obj:GetChild("ButtonTips2")
    local btn_remove = obj:GetChild("ButtonTips3")
    local btn_petskill = obj:GetChild("btnPetSkill"):GetChild("icon"):GetChild("icon")
    local petred = obj:GetChild("btnPetSkill"):GetChild("n11")
    petred.visible = false
    btn_rename:GetChild("Tips").text = getLanguage("UIBattleManyTeams1006")
    btn_top:GetChild("Tips").text = getLanguage("UIBattleManyTeams1007")
    btn_remove:GetChild("Tips").text = getLanguage("UIBattleManyTeams1008")

    local curTowerType = logicMgr.TowerManager.getClimbType()
    local limit = nil
    --职业爬塔
    if fightType == EnumConst.FightTypeConst.TOWER then
        if G.dataTable["t_towertype"][tostring(curTowerType)].f_Group == EnumConst.TowerType.Advanced then
            local canSelectHeroTypes = logicMgr.TowerManager.getAdvancedTowerHeroType()
            limit = {}
            for k, v in pairs(canSelectHeroTypes) do
                limit[v] = v
            end
        end
    end

    local editor = false
    if m_team_list[index + 1] then
        editor = true
        ctr_mask.selectedIndex = 0
        obj:GetController("ButtonUse").selectedIndex = 1

        local same = true
        --SkillManager.getSupSkillIdByFormationType(self.formationType) and
        local use_skill = SkillManager.getSupSkillIdByFormationType(self.formationType) or 0
        if m_team_list[index + 1].skill ~= use_skill then
            same = false
        end
        if same then
            same = CompareTable(m_team_list[index + 1].team, self.formations[self.formationsIndex])

            if same then
                ctr_choose.selectedIndex = 1
                ctr_buttonUse.selectedIndex = 2
            else
                ctr_choose.selectedIndex = 0
                ctr_buttonUse.selectedIndex = 1
            end
        else
            ctr_choose.selectedIndex = 0
            ctr_buttonUse.selectedIndex = 1
        end
        --ctr_choose.selectedIndex = m_choose_team == index + 1 and 1 or 0
        tips.text = m_team_list[index + 1].name

        local sk = G.dataTable["t_skillshow"][tostring(m_team_list[index + 1].skill)];
        if sk then
            img_supskill.url = "ui://SkillAtlas/" .. sk.f_SkillIcon
        else
            img_supskill.url = ""
        end
        local petsk = G.dataTable["t_skillshow"][tostring(m_team_list[index + 1].petSkill)];
        if petsk then
            btn_petskill.url = "ui://SkillAtlas/" .. sk.f_SkillIcon
        else
            btn_petskill.url = ""
        end
    else
        ctr_buttonUse.selectedIndex = 0
        ctr_choose.selectedIndex = 0
        if (index + 1) - table.getn(m_team_list) == 1 then
            ctr_mask.selectedIndex = 0
            editor = true
        else
            ctr_mask.selectedIndex = 1
            editor = false
        end
        tips.text = getLanguage("UIBattleManyTeams1001") .. (index + 1)
        obj:GetController("ButtonUse").selectedIndex = 0
        img_supskill.url = ""
    end

    ctr_btnlist.selectedIndex = editor and 1 or 0

    btn_rename.onClick:Clear()
    btn_rename.onClick:Add(function()
        if m_team_list[index + 1] then
            showUI(PanelResNames.UITeamsRename, m_team_list[index + 1])
        else
            UISysTips.AddMsg(getLanguage("UIBattleManyTeams1010"))
        end
    end)
    btn_top.onClick:Clear()
    btn_top.onClick:Add(function()
        if m_team_list[index + 1] then
            FormationManager.req_FormationSort(index + 1)
        else
            UISysTips.AddMsg(getLanguage("UIBattleManyTeams1010"))
        end
    end)
    btn_remove.onClick:Clear()
    btn_remove.onClick:Add(function()
        if m_team_list[index + 1] then
            local pop = CtrlManager.GetCtrl(PanelNames.UICommonPop)
            pop.Init(100, function(flag)
                if flag then
                    FormationManager.req_FormationRemove(index + 1)
                else

                end
            end)
        else
            UISysTips.AddMsg(getLanguage("UIBattleManyTeams1010"))
        end
    end)

    heros.itemRenderer = function(child, it)
        local ctr_state = it:GetController("state")
        local Btn_Hero = it:GetChild("Btn_Hero")
        local ctr_hadBattle = Btn_Hero:GetController("ctrlHadBattle")
        local ctr_hadselect = Btn_Hero:GetController("HadSelect")
        local ctr_heroPos = it:GetController("HeroPos")
        local ctr_herodead = Btn_Hero:GetController("herodead")

        if m_team_list[index + 1] then
            local pid = m_team_list[index + 1].team[child + 1]
            ctr_state.selectedIndex = pid == "0" and 0 or 1
            local h-- = HeroManager.getHeroDatabyPartnerId(pid)
            for k, v in pairs(self.tableHeros) do
                if pid == v.partnerId then
                    h = v
                    break
                end
            end

            if pid ~= "0" then
                local lua = CtrlManager.GetCtrl(PanelNames.HeadRectItem)
                lua.initData(Btn_Hero, h)

                if ctr_heroPos then
                    ctr_heroPos.selectedIndex = child + 1
                end

                if limit and not limit[h.type] then
                    ctr_herodead.selectedIndex = 1
                else
                    ctr_herodead.selectedIndex = 0
                end
            else
                ctr_heroPos.selectedIndex = 0
                ctr_herodead.selectedIndex = 0
            end
            if ctr_choose.selectedIndex == 1 then
                if h then
                    ctr_hadBattle.selectedIndex = 1--h["state"] == EnumConst.HeroHeadStateEnum.BATTLE and 1 or 0
                else
                    ctr_hadBattle.selectedIndex = 0
                end
            else
                ctr_hadBattle.selectedIndex = 0
            end

            if self.formationsMax > 1 then
                local hadselect
                for k, v in pairs(self.formations) do
                    if k ~= self.formationsIndex then
                        for i = 1, #v do
                            if v[i] == pid then
                                hadselect = true
                                break
                            end
                        end
                    end
                end

                ctr_hadselect.selectedIndex = hadselect and 1 or 0
            else
                ctr_hadselect.selectedIndex = 0
            end
        else
            ctr_state.selectedIndex = 0
            ctr_heroPos.selectedIndex = 0
            ctr_herodead.selectedIndex = 0
        end
    end
    heros.numItems = 6
    btn_use.onClick:Clear()
    btn_use.onClick:Add(function()
        self:SelectTeam(index)
    end)

    btn_bg.onClick:Clear()
    btn_bg.onClick:Add(function()
        if editor then
            FormationManager.SetFocus(index + 1)
            local ctrlItem = CtrlManager.GetCtrl(PanelNames.TeamHeroItem);
            ctrlItem.onClear();
            ctrlItem.Destroy();
            showUI(PanelResNames.UIBattleTeamEditor, EnumConst.FightTypeConst.FormationEditor, nil, function(team)
                local sup = SkillManager.getSupSkillIdByFormationType(EnumConst.FormationType.FormationEditor) or 0
                FormationManager.req_SetFormation(index + 1, team[1])
                closeUI(PanelResNames.UIBattleTeamEditor)
                self:refresh()
            end)
        end
    end)
end


--刷新编队状态
function UIBattleTeam:RefreshTeamEditor()
    local b = logicMgr.FormationManager.IsOpen()
    if b then
        b = not FormationManager.IsInEditor()
    end
    self.ctr_teamShow.selectedIndex = b and 1 or 0
    --self.ctr_teamListShow.selectedIndex = b and 1 or 0
end

function UIBattleTeam:onClickTeamEditor()
    if self.ctr_teamListShow.selectedIndex == 1 then
        self.ctr_teamListShow.selectedIndex = 0
    else
        -- m_choose_team = nil
        self.ctr_teamListShow.selectedIndex = 1
        m_team_list = logicMgr.FormationManager.GetAllFormation()

        self.ctr_teamIsNil.selectedIndex = 1
        self.Teamlist.numItems = logicMgr.FormationManager.GetMax()
    end
end

function UIBattleTeam:refresh()
    for i = 1, #self._counterpointList do
        self.restrainObjList[1][i].visible = false
        self.restrainObjList[2][i].visible = false
    end
    self.tipsText.text = self.isShowTitle and getLanguage("BattleTeamTips2") or getLanguage("BattleTeamTips1")
    self.text_clearRequist.text = string.format(getLanguage("TeamsTips001"), self.formationsMax)
    self.btnManual.visible = false
    if logicMgr.FuncOpenManager.isOpen(208) then
        self.btnManual.visible = true
    end
    if (fightType == EnumConst.FightTypeConst.DUNGEON or fightType == EnumConst.FightTypeConst.StoryBattle) and next(logicMgr.BattlePlaybackManager.GetGroupBossHistory()) ~= nil then
        self.tipsText.text = "该场战斗已经打响，不能进行英雄养成"
    elseif fightType == EnumConst.FightTypeConst.GuildBattlePlus then
        self.tipsText.text = ""
    end
    local help_pos_idx = nodeCount + 1
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HelpMan, false) then
        self.leftRect[help_pos_idx].visible = true
        self.leftRole[help_pos_idx].visible = true
        self.rightPos[help_pos_idx].visible = true
    else
        self.leftRect[help_pos_idx].visible = false
        self.leftRole[help_pos_idx].visible = false
        self.rightPos[help_pos_idx].visible = false
    end
    for j = 1, self.formationsMax do
        for i = 1, nodeCount do
            self.tabHeroPosDataTemp[j][i] = {}

        end
        self.helpMan[j] = {}
    end
    self.tabHeroPosData = {}
    logicMgr.FriendBattleManager.ClearTeam()
    --self.lastFormationPosData = {}--上一次刷新阵容时的阵容
    self:GetController("teamId"):SetSelectedIndex(0)
    if self.teamController.selectedIndex ~= 0 then
        self.teamController:SetSelectedIndex(0)
    end
    self:onClickType()
    for k, v in pairs(self.tableFormationIndex) do
        local selCtrl = v:GetController("select")
        if selCtrl then
            if self.formationsIndex == k then
                selCtrl.selectedIndex = 1
            else
                selCtrl.selectedIndex = 0
            end
        end
    end
    if self.formationsMax > 1 then
        for i = 1, self.formationsMax do
            local go = self.tableFormationIndex[i]
            go.visible = true
            go.onClick:Clear()
            go.onClick:Add(function()
                self.isChangTeam = true;
                self.lastHelpManId = self.helpMan[self.formationsIndex].partnerModelId;
                self:onClickItemIndex(i)
                self.isChangTeam = false;
            end);
            go:GetController("Clear").selectedIndex = 0;
            if fightType == EnumConst.FightTypeConst.DUNGEON or fightType == EnumConst.FightTypeConst.StoryBattle then
                local data = logicMgr.BattlePlaybackManager.GetGroupBossHistory(i)
                if data and data.record and data.record.win == 1 then
                    go:GetController("Clear"):SetSelectedIndex(1)
                    go.onClick:Clear()
                    go.onClick:Add(function()
                        UISysTips.AddMsg(getLanguage("ErrorCode_1016"));
                    end);
                end
            elseif fightType == EnumConst.FightTypeConst.GuildBattlePlus then
                if param.formationIsOver and param.formationIsOver[i] then
                    go:GetController("Clear"):SetSelectedIndex(1)
                end
            end
        end
    end

    for i = self.formationsMax + 1, #self.tableFormationIndex do
        self.tableFormationIndex[i].onClick:Clear();
        self.tableFormationIndex[i].visible = false;
    end

    self:RefreshBossBtn()
    self:initBg()
    if fightType == EnumConst.FightTypeConst.DUNGEON then
        if self.formationsMax > 1 then
            self.ctrlIfMainBattle:SetSelectedIndex(4)
        else
            self.ctrlIfMainBattle:SetSelectedIndex(1)
        end
        self.topChapterPanel:Refresh()
        self:RefreshChapterRewardBtn();
    elseif fightType == EnumConst.FightTypeConst.RankBattle then
        self.ctrlIfMainBattle:SetSelectedIndex(2)
    elseif fightType == EnumConst.FightTypeConst.DarkStreet then
        self.ctrlIfMainBattle:SetSelectedIndex(3)
        self.darkStreetPanel:Refresh()
    elseif fightType == EnumConst.FightTypeConst.StoryBattle then
        self.ctrlIfMainBattle:SetSelectedIndex(6)
        local id = 0
        if dungeonHandler.hardData.maxPassDungeon == 0 then
            id = 101
        else
            id = G.dataTable["t_stagehardmode"][tostring(dungeonHandler.hardData.maxPassDungeon)].f_NextStage
        end
        self.topChapterPanel:RefreshHard(id)
    else
        self.ctrlIfMainBattle:SetSelectedIndex(0)
    end
    --[[if fightType == EnumConst.FightTypeConst.ARENA then
        if self.formationType == 3 or self.formationType == 4 then
            self.ctrlIfMainBattle:SetSelectedIndex( 5 )
        end
    end--]]
    self:initFormation()
    self:rendererFormation()
    self:initEnemyFormation()
    if self.isInit then
        self.isInit = false
    end
    self:refreshCombinationSkill();

end
--拖动开始
function UIBattleTeam:onDragStartFunc(item)
    if self.clearController.selectedIndex ~= 0 then
        item.draggable = false;
        return ;
    end
    item.draggable = true
    if fightType == EnumConst.FightTypeConst.RankBattle and logicMgr.RankBattleManager.BanPick() then
        if logicMgr.RankBattleManager.LastIsChoose(item.data.partnerModelId) then
            item.draggable = false
            return
        else
            item.draggable = true
        end
    else
        item.draggable = true
    end
    if item.draggable and item.data.state ~= 0 and item.data.state ~= nil then
        AudioManager.Play(1031)
        --item.parent:SetChildIndex(item, item.parent:GetChildIndex(self.titleNode) - 1)
        local ctrlItem = CtrlManager.GetCtrl(PanelNames.TeamHeroItem)
        local type = self.isShowTitle and 1 or 0
        ctrlItem.updateTitle(item:GetChild("title"), item.data, type, item.data.teamIdx, fightType, self.formationType)

        --item:GetChild("title").visible = true
        --local titleItem = logicMgr.UIShowManager.getTeamHeroItem(item.data.teamIndex, item.data.teamIdx)
        --titleItem.visible = false
    end
end

function UIBattleTeam:onDragMoveFunc(item)
    if self.isMove == false then
        return ;
    end
    local index = 0;
    local ctrlItem = CtrlManager.GetCtrl(PanelNames.TeamHeroItem);
    --ctrlItem.updateTitlePos(item, item.data, item.data.teamIdx);
    for i = 1, nodeCount + 1 do
        if self.leftRole[i] == item then
            index = i;
            break ;
        end
    end
    local inPos = 0;
    for i = 1, nodeCount + 1 do
        if isIntersect(self.leftRect[i], item) == true then
            inPos = i;
            break
        end
    end
    if inPos ~= 0 then
        if fightType == EnumConst.FightTypeConst.RankBattle and logicMgr.RankBattleManager.BanPick() then
            if logicMgr.RankBattleManager.LastIsChoose(item.data.partnerModelId) then
                return
            end
            local modelId
            if inPos > nodeCount then
                modelId = self.helpManId[self.formationsIndex]
            else
                modelId = self.tabHeroPosData[inPos].partnerModelId
            end
            if logicMgr.RankBattleManager.LastIsChoose(modelId) then
                return
            end
        end
    end
    for i = 1, nodeCount + 1 do
        if (index ~= i) then
            self.leftRole[i]:SetPosition(self.leftRect[i].x, self.leftRect[i].y, 0);
            ctrlItem.updateTitlePos(self.leftRole[i], self.leftRole[i].data, self.leftRole[i].data.teamIdx, fightType, nodeCount + 1);
        end
    end
    if (inPos ~= 0) then
        if (inPos ~= index) then
            self.leftRole[inPos]:SetPosition(self.leftRect[index].x, self.leftRect[index].y, 0);
            ctrlItem.updateTitlePos(self.leftRole[inPos], self.leftRole[inPos].data, self.leftRole[inPos].data.teamIdx, fightType, nodeCount + 1);
        end
    end

end
function UIBattleTeam:onDragEndFunc(item)
    if self.isMove == true then
        self.isMove = false;
    end
    --item:GetChild("title").visible = false;
    --logicMgr.UIShowManager.getTeamHeroItem(item.data.teamIndex, item.data.teamIdx).visible = true;
    AudioManager.Play(1032)

    local index = 0;
    for i = 1, nodeCount + 1 do
        if self.leftRole[i] == item then
            index = i;
            break ;
        end
    end
    local inPos = 0;
    for i = 1, nodeCount + 1 do
        if isIntersect(self.leftRect[i], item) == true then
            inPos = i;
            break
        end
    end
    if (inPos ~= 0) then
        if fightType == EnumConst.FightTypeConst.RankBattle and logicMgr.RankBattleManager.BanPick() then
            if logicMgr.RankBattleManager.LastIsChoose(item.data.partnerModelId) then
                return
            end
            local modelId
            if inPos > nodeCount then
                modelId = self.helpManId[self.formationsIndex]
            else
                modelId = self.tabHeroPosData[inPos].partnerModelId
            end
            if logicMgr.RankBattleManager.LastIsChoose(modelId) then
                self:changePosByIndex(index, index)
            else
                self:changePosByIndex(index, inPos);
            end
        else
            self:changePosByIndex(index, inPos);
        end
    else
        self:changePosByIndex(index, index)
    end
    item:SetPosition(self.leftRect[index].x, self.leftRect[index].y, 0);
    if (index ~= 0) then
        item.parent:SetChildIndex(item, self.leftIndex[index]);
    end
end

function UIBattleTeam:addEvent()
    self.resetHeroBtn.onClick:Add(function()
        if currentFightType == EnumConst.FightTypeConst.DUNGEON then
            TAManager.TrackByDictionary("ui_battle_team_reset")
        end
        for i = 1, nodeCount + 1 do
            if i >= nodeCount + 1 then
                if self.playerIds[i] and tostring(self.playerIds[i]) ~= "0" then
                    self:BorrowInfo(self.tabHeroPosData[i])
                else
                    if fightType == EnumConst.FightTypeConst.RankBattle then
                        self:onClickHero(self.helpMan[self.formationsIndex], self.tabHeroItem[tonumber(tostring(self.helpManId[self.formationsIndex]))]);
                    else
                        self:onClickHero(self.helpMan[self.formationsIndex], self.tabHeroItem[tostring(self.helpManId[self.formationsIndex])]);
                    end
                end
            else
                if self.tabHeroPosData[i] and self.tabHeroPosData[i]["partnerId"] then
                    if self.playerIds[i] and tostring(self.playerIds[i]) ~= "0" then
                        self:BorrowInfo(self.tabHeroPosData[i])
                    else
                        self:onClickHero(self.tabHeroPosData[i], self.tabHeroItem[self.tabHeroPosData[i]["partnerId"]]);
                    end
                end
            end
        end
    end)
    self:RegisterOnClick(self.btnShowDec, self.changeHeroItemTitle);
    self:RegisterOnClick(self.BtnGo, self.onClick_gotoHeroMain)
    self:RegisterOnClick(self.btnChapterReward, self.onClickChapterReward);
    self:RegisterOnClick(self.btnShowDebris, self.changeShowDebris);
    self:RegisterOnClick(self.supSkillLeftBtn, function()
        self:onOpenSupSkillSelect(0)
    end);
    self:RegisterOnClick(self.petSkill, function()
        self:onOpenSupSkillSelect(1)
    end);
    self:RegisterOnClick(self.btn_teamEditor, self.onClickTeamEditor)
    self:RegisterOnClick(self.btnBack, self.onClickBack1);
    self:RegisterOnClick(self.btnBoss, self.onClickBoss);
    self:RegisterOnClick(self.btnManual, self.onClickManual);
    self:RegisterOnClick(self.btnQuickChange, self.onClickQuickChange);
    self:RegisterOnClick(self.Btn_Add, self.OnClickChallengeBtnAdd)
    self:RegisterOnClick(self.btn_close, self.onClick_CloseTeamEditor)
    self:RegisterOnClick(self.btn_bgclose, self.onClick_CloseTeamEditor)
    self:RegisterOnClick(self.btnSkip, self.onClickChangeSkipState);
    self:RegisterOnClick(self.Btn_HeroTactics, self.onClickHeroTactics);
    self:RegisterOnClick(self.btnPetShow, function()
        local paramTeamBonus = {}
        paramTeamBonus.tabHeroPosData = self.tabHeroPosData;
        paramTeamBonus.formationsIndex = self.formationsIndex;
        paramTeamBonus.helpMan = self.helpMan;
        showUI(PanelNames.UITeamBonus, paramTeamBonus);
    end)
    self:RegisterOnClick(self:GetChild("Tips"), function()
        showUI(PanelNames.UITeamBonus);
    end)
    self:RegisterOnClick(self:GetChild("Img_Lock3"), function()
        logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HelpMan, true, self:GetChild("Img_Lock3"))
    end)
    self:RegisterOnClick(self:GetChild("Img_Lock4"), function()
        logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HelpMan, true, self:GetChild("Img_Lock4"))
    end)
end

function UIBattleTeam:LocalListenEvent()
    self:GetController("team").onChanged:Add(function()
        self:onClickType()
    end);
    self:RegisterEvent(Config.EventType.AssistantSkill, self.refreshSupSkill);
    self:RegisterEvent(Config.EventType.ChangePetSkill, self.freshPetSkill)
    self:RegisterEvent(Config.EventType.BorrowFriendHero, self.BorrowInfo);
    self:RegisterEvent(Config.EventType.GuideTeamRoleTouch, self.GuideTeamRoleTouch)
    self:RegisterEvent(Config.EventType.GuideFindHeroId, self.GuideFindHeroIdMsg)
    self:RegisterEvent(Config.EventType.TouchAnyKey, self.TouchAnyKeyMsg)
    self:RegisterEvent(Config.EventType.SetDefFormation, function()
        self:setSelfFormationByType(fightType, param);
        self:refresh()
    end)
    self:RegisterEvent(Config.EventType.BtnFriendCtr, function(self, msg)
        self.friendCtrl:SetSelectedIndex(msg[1])
        self.teamController:SetSelectedIndex(0)
        if self.curTabType ~= 0 then
            self.curTabType = 0
            self:onClickType()
        end
        self.dynamicList.numItems = #self.tabOwner
    end)
    self:RegisterEvent(Config.EventType.RankBattleTeam, self.RankBattleTeam)
    self:RegisterEvent(Config.EventType.RankBattleEnemylock, self.BPformation)
    self:RegisterEvent(Config.EventType.BPReConnect, self.BPformation)
end

function UIBattleTeam:LocalCloseEvent()
    self:UnRegisterEvent(Config.EventType.AssistantSkill, self.refreshSupSkill);
    self:UnRegisterEvent(Config.EventType.BorrowFriendHero, self.BorrowInfo);
    self:UnRegisterEvent(Config.EventType.GuideTeamRoleTouch, self.GuideTeamRoleTouch)
    self:UnRegisterEvent(Config.EventType.GuideFindHeroId, self.GuideFindHeroIdMsg)
    self:GetController("team").onChanged:Clear();
end

function UIBattleTeam:BPformation(msg)
    if logicMgr.RankBattleManager.BanPick() then
        self:setOppoFormationByType(fightType, param)
        self:initEnemyFormation()
        self.dynamicList.numItems = #self.tabOwner
    end
    if msg then
        self:setSelfFormationByType(fightType, msg)
        self:initFormation()
        self:rendererFormation()
    end
end

function UIBattleTeam:RankBattleTeam(fun, isFire)
    local info = { 0, 0, 0, 0, 0, 0 }
    local flag = false;
    for k, v in ipairs(self.tabHeroPosData) do
        if v.partnerModelId then
            info[k] = v.partnerModelId
            flag = true;
        end
    end
    local helpId = self.helpMan[self.formationsIndex]["partnerModelId"]
    if helpId then
        info[6] = helpId
        flag = true;
    end
    if isFire then
        if not logicMgr.RankBattleManager.BanPick() then
            RankBattleHandler.ReqRankBattleLock(info, self.battleInfo.helpSkillId)
        else
            local myformation = logicMgr.RankBattleManager.GetBPFormation()
            for k, v in ipairs(myformation) do
                if v and v ~= 0 then
                    info[k] = 0
                end
            end
            local bpinfo = {}
            for k, v in ipairs(info) do
                if v and v ~= 0 then
                    local item = HeroSite.New();
                    item.heroId = v
                    item.site = k
                    table.insert(bpinfo, item)
                end
            end
            RankBattleHandler.BPReqRankBattleLock(bpinfo)
        end
        return
    end
    if flag then
        if not logicMgr.RankBattleManager.BanPick() then
            RankBattleHandler.ReqRankBattleLock(info, self.battleInfo.helpSkillId)
        else
            local myformation = logicMgr.RankBattleManager.GetBPFormation()
            for k, v in ipairs(myformation) do
                if v and v ~= 0 then
                    info[k] = 0
                end
            end
            local bpinfo = {}
            for k, v in ipairs(info) do
                if v and v ~= 0 then
                    local item = HeroSite.New();
                    item.heroId = v
                    item.site = k
                    table.insert(bpinfo, item)
                end
            end
            RankBattleHandler.BPReqRankBattleLock(bpinfo)
        end
    else
        UISysTips.AddMsg(getLanguage("ErrorCode_3404"))
        return
    end
    if fun then
        fun(flag);
    end
end

function UIBattleTeam:OnDestroy()
    if not HelperFunc.IsNull(self.battleMapGo) then
        Util.Lua_SetLocalPositionXYZ(self.battleMapGo, self.originalPos.x, self.originalPos.y, self.originalPos.z);
        Util.Lua_SetLocalScaleXYZ(self.battleMapGo, self.originalScale.x, self.originalScale.y, self.originalScale.z);
        Util.Lua_SetLocalRotationXYZ(self.battleMapGo, self.originalRotation.x, self.originalRotation.y, self.originalRotation.z);
        self.battleMapGo.gameObject:SetActive(false);
        Util.SetLayerMask(self.battleMapGo.gameObject, "Default", true);
    end
    for k, v in pairs(self.leftRole) do
        v.onClick:Clear();
    end
    if self.topChapterPanel then
        self.topChapterPanel:OnDestroy()
    end
    if self.timerId then
        utimer.remove(self.timerId)
        self.timerId = nil
    end
    self.topChapterPanel = nil
    self:RemoveEffect()
    if self.darkStreetPanel then
        self.darkStreetPanel:OnDestroy()
    end
    self.darkStreetPanel = nil
    --self:RemoveTimeCall(self.RefreshDarkStreetTime)
    --self.darkStreetTimerId = nil

    if self.goWrapper then
        self.goWrapper:Dispose()
        self.goWrapper = nil
    end
    if self.mapObj then
        Util.Lua_SetLocalPositionXYZ(self.mapObj.transform, 0, 1000, 0);
        destroy(self.mapObj);
        self.mapObj = nil
        mapName = ""
        --self.mapObj.gameObject:SetActive(false)
    end

    self.trialsBuff = nil
    --
    --if self.teamHeroItemList then
    --    for key, value in pairs(self.teamHeroItemList) do
    --        value:Destroy()
    --    end
    --    self.teamHeroItemList = nil
    --end
end

function UIBattleTeam:changeShowDebris()
    self.isShowDebris = not self.isShowDebris;
    if self.isShowDebris then
        UISysTips.AddMsg(getLanguage("DebrisCheckTips1"));
    else
        UISysTips.AddMsg(getLanguage("DebrisCheckTips2"));

    end
    local ctrlItem = CtrlManager.GetCtrl(PanelNames.TeamHeroItem);
    for i = 1, #self.tabHeroPosData do
        if nodeCount >= i then
            local role = self.leftRole[i];
            local itemData = self.tabHeroPosData[i];
            if ctrlItem ~= nil then
                ctrlItem.updateDebris(role, itemData, self.isShowDebris);
            end
        end
    end
    local role = self.leftRole[nodeCount + 1];
    local itemData = self.helpMan[self.formationsIndex];
    if ctrlItem ~= nil then
        --初始装备信息
        ctrlItem.updateDebris(role, itemData, self.isShowDebris);
    end

    self:onClickType();
end

function UIBattleTeam:onClick_gotoHeroMain()
    self:onClickBack();
    UIBottom.enterPlayer()
end

function UIBattleTeam:changeHeroItemTitle()
    if currentFightType == EnumConst.FightTypeConst.DUNGEON then
        TAManager.TrackByDictionary("ui_battle_team_change_info")
    end
    --self.pageTips:GetController("TipsShow").selectedIndex = 0;
    self.isShowTitle = not self.isShowTitle;
    self.tipsText.text = self.isShowTitle and getLanguage("BattleTeamTips2") or getLanguage("BattleTeamTips1");
    if (fightType == EnumConst.FightTypeConst.DUNGEON or fightType == EnumConst.FightTypeConst.StoryBattle) and next(logicMgr.BattlePlaybackManager.GetGroupBossHistory()) ~= nil then
        self.tipsText.text = "该场战斗已经打响，不能进行英雄养成";
    end
    logicMgr.FriendBattleManager.ShowTitle(self.isShowTitle)
    local type = self.isShowTitle and 1 or 0;
    local ctrlItem = CtrlManager.GetCtrl(PanelNames.TeamHeroItem);
    for i = 1, #self.tabHeroPosData do
        if nodeCount >= i then
            local itemData = self.tabHeroPosData[i];
            if ctrlItem ~= nil then
                ctrlItem.updateTitle(nil, itemData, type, i, fightType, self.formationType);
            end
        end
    end
    local itemData = self.helpMan[self.formationsIndex];
    if ctrlItem ~= nil then
        --初始装备信息
        ctrlItem.updateTitle(nil, itemData, type, nodeCount + 1, fightType, self.formationType);
    end
    self:initEnemyFormation()
    self:onClickType();
    FireEvent(Config.EventType.FriendBorrowHeroList)
end

function UIBattleTeam:OnEnable()
    logicMgr.ArenaManager.setSomeBattleSkip(false);
    self.friendCtrl.selectedIndex = 0
    self.competeBattleWinsCtrl.selectedIndex = 0;
    self.fguiObj.fairyBatching = true;
    self.isClickBattle = false
    self.isShowTitle = false;
    self.isShowDebris = false;
    self.tableLeaseHeros = {};
    self.tabLeaseAndOwnerHeros = {};
    self.tabLeaseAndOwnerHeroIndex = {};
    if self.isFriendBattle then
        showUI(PanelNames.UITeam)
        self.ctr_teamShow.selectedIndex = 0
    end
    if self.isNotNeedEnable then
        return
    end
    self.btnShowDebris.visible = false;
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UIBattleTeam, Config.FuncOpenType.SupSkill, self.supSkillLeftBtn.name, self.supSkillLeftBtn);
    --logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UIBattleTeam, Config.FuncOpenType.PetPartAttr, self.petSkill.name.."pet", self.petSkill);
    FuncOpenManager.addStatusCtr(PanelNames.UIBattleTeam, Config.FuncOpenType.SupSkill, self.supSkillRight.name, self.supSkillRight);
    FuncOpenManager.addStatusCtr(PanelNames.UIBattleTeam, Config.FuncOpenType.BattleTeamPet, self.btnPetShow.name, self.btnPetShow);
    if fightType == EnumConst.FightTypeConst.ARENA then
        FuncOpenManager.addStatusCtr(PanelNames.UIBattleTeam, Config.FuncOpenType.arenaQuickSkip, self.btnSkip.name, self.btnSkip);
    elseif fightType == EnumConst.FightTypeConst.FriendAttack then
        FuncOpenManager.addStatusCtr(PanelNames.UIBattleTeam, Config.FuncOpenType.friendQuickSkip, self.btnSkip.name, self.btnSkip);
    end

    self.helpMan = { {}, {}, {} };
    self.helpManId = {};
    self.enemyHelpMan = { {}, {}, {} };
    self.enemyHelpManId = { 0, 0, 0 };

    if self.stageConfig == nil then
        self.stageConfig = G.dataTable["t_stage"];
    end
    if fightType == EnumConst.FightTypeConst.RankBattle then
        self.tableHeros = logicMgr.HeroManager.getAllRankHero()
    else
        if fightType == EnumConst.FightTypeConst.DUNGEON then
            local leaseHeros = logicMgr.DungeonRandomEventManager.getLeaseHero();
            if leaseHeros ~= nil then
                self.tableLeaseHeros = leaseHeros;
            end
        end
        self.tableHeros = logicMgr.HeroManager.getOwnerHeroList(false, nil, true);
    end
    --logicMgr.HeroManager.SetMyHeroSkin(self.tableHeros)
    table.sort(self.tableLeaseHeros, self.sortHero);
    for i = 1, #self.tableLeaseHeros do
        self.tableLeaseHeros[i]["state"] = 0;
        local localModelId = self.tableLeaseHeros[i]["partnerModelId"];
        self.tabLeaseAndOwnerHeros[localModelId] = { leaseItemGo = nil, ownerItemGo = nil };
        self.tabLeaseAndOwnerHeroIndex[localModelId] = { leaseIndex = i, ownerIndex = 0 };
    end

    table.sort(self.tableHeros, self.sortHero);
    for i = 1, #self.tableHeros do
        logicMgr.HeroManager.setHeroState(self.tableHeros[i].partnerId, false, EnumConst.HeroHeadStateEnum.BATTLE, fightType, self.tableHeros[i]);
        if logicMgr.StrangeFragmentManager.GetFragmentInfoByPartnerId(self.tableHeros[i].partnerId) and not self.btnShowDebris.visible then
            self.btnShowDebris.visible = true;
        end
        self.tableHeros[i]["state"] = 0
        local localModelId = self.tableHeros[i]["partnerModelId"];
        if self.tabLeaseAndOwnerHeroIndex[localModelId] ~= nil then
            self.tabLeaseAndOwnerHeroIndex[localModelId].ownerIndex = i;
        end
    end

    self.battleBossFunction = battleAct
    self.backFunction = backAct;
    self.curFightType = fightType;
    self.formationsIndex = 1
    self.formationsMax = 1
    if fightType == EnumConst.FightTypeConst.INSTANCE then
        self.formationsMax = 2
        self.mythicShow.selectedIndex = 1
        local starInfo = logicMgr.MythicDungeonsProManager.levelInfo()
        local cfg = dataTable.getDataTableByStringId("t_mythicdungeons", MythicDungeonsProManager.getLayer())
        for i = 1, 3 do
            self.starObj[i].ctrl.selectedIndex = 0
            local condition_1 = cfg["f_MythicStarParameter0" .. i][1]
            local condition_2 = cfg["f_MythicStarParameter0" .. i][2] or 0
            if cfg["f_MythicStarTpye0" .. i] == 4 then
                condition_2 = getLanguage("HeroType" .. condition_2)
            end
            if cfg["f_MythicStarTpye0" .. i] == 9 then
                condition_1 = getLanguage("MythicHeroType0" .. condition_1)
            end
            if cfg["f_MythicStarTpye0" .. i] == 7 then
                condition_1 = getLanguage("HeroName" .. condition_1)
            end
            if cfg["f_MythicStarTpye0" .. i] == 2 then
                condition_1 = condition_1 / 1000
            end
            self.starObj[i].desc.text = string.format(getLanguage(cfg["f_MythicStarLanguage0" .. i]), condition_1, condition_2)
        end
        if #starInfo > 0 then
            for _, v in ipairs(starInfo) do
                self.starObj[v].ctrl.selectedIndex = 1
            end
        end
    elseif fightType == EnumConst.FightTypeConst.ARENA then
        if param.arena_type == EnumConst.ArenaBattleType.TeamCross then
            self.formationsMax = 3
        end
    elseif fightType == EnumConst.FightTypeConst.DUNGEON then
        self.formationsMax = logicMgr.MapManager.getStageNeedTeamNum();
        self.formationsIndex = logicMgr.BattlePlaybackManager.GetGroupBossJoinGroupId()
    elseif fightType == EnumConst.FightTypeConst.SoloChaosTest then
        self.formationsMax = 3
    elseif fightType == EnumConst.FightTypeConst.GuildBattlePlus then
        self.formationsMax = param.formationNum or 1;
        self.formationsIndex = self.formationsMax;
        for i = 1, self.formationsMax do
            if not (param.formationIsOver and param.formationIsOver[i]) then
                self.formationsIndex = i;
                break ;
            end
        end
    elseif fightType == EnumConst.FightTypeConst.StoryBattle then
        self.formationsMax = logicMgr.MapManager.getStoryBattleNeedTeamNum()
        self.formationsIndex = logicMgr.BattlePlaybackManager.GetGroupBossJoinGroupId(EnumConst.FightTypeConst.StoryBattle)
    elseif fightType == EnumConst.FightTypeConst.TRIAL then
        self:showTrialsPoints()
        self:showTrialsBuff()
    end
    self.ctrlNumTeams.selectedIndex = self.formationsMax > 1 and self.formationsIndex or 0
    self:EnableHeroTypeBtn();
    ----获取双方阵容数据
    self:setSelfFormationByType(fightType, param);
    self:setOppoFormationByType(fightType, param);
    self:refreshSupSkill();
    self:freshPetSkill()
    self:refresh()
    if self.formationType == EnumConst.FightTypeConst.FriendDefend or self.formationType == EnumConst.FightTypeConst.FriendAttack then
        self.isFriendBattle = true
        self.ctr_teamShow.selectedIndex = 0
        self.playerIds = logicMgr.FriendBattleManager.GetPlayerIds(self.formationType)
    else
        self.isFriendBattle = false
    end
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HelpMan) then
        self.supCtrl.selectedIndex = 0
    else
        self.supCtrl.selectedIndex = 1
    end
    --self.isNeedOpenHeadMenu = false;
    --[[if isOpenUI(PanelResNames.UIHeadMenu) then
        closeUI(PanelResNames.UIHeadMenu);
        if not isOpenUI(PanelNames.UIBigMap) then
            self.isNeedOpenHeadMenu = true
        end

    end]]
    self:LocalListenEvent();
end

function UIBattleTeam:RefreshSkipState()
    self.showBtnSkipCtrl.selectedIndex = 1;
    local battleSkipValue = GetPlayerPrefs("TeamCrossSkip" .. logicMgr.HeroManager.GetRoleInfo("playerId")) or 1;
    local isBattleSkip = battleSkipValue == "1";
    logicMgr.ArenaManager.setSomeBattleSkip(isBattleSkip);
    local str = isBattleSkip and "PVPSkipBtn_Text2" or "PVPSkipBtn_Text1";
    self.btnSkip:GetController("state").selectedIndex = isBattleSkip and 1 or 0;
    self.btnSkip:GetChild("title").text = getLanguage(str);
end

function UIBattleTeam:RefreshBossBtn()
    if self.formationType == EnumConst.FormationType.MythicDungeons then
        if self.formationsIndex == 1 then
            self.btnController:SetSelectedIndex(2)
        else
            self.btnController:SetSelectedIndex(0)
        end
    elseif fightType == EnumConst.FightTypeConst.ARENA and
            (self.formationType == EnumConst.FormationType.ArenaDef or self.formationType == EnumConst.FormationType.CrossArenaDef)
    then
        self.btnController:SetSelectedIndex(1)
    elseif self.formationType == EnumConst.FormationType.TeamCrossArenaDef and fightType == EnumConst.FightTypeConst.ARENA then
        if self.formationsIndex == 1 or self.formationsIndex == 2 then
            self.btnController:SetSelectedIndex(2)
        else
            self.btnController:SetSelectedIndex(1)
        end
    elseif self.formationType == EnumConst.FormationType.TeamCrossArenaAtk and fightType == EnumConst.FightTypeConst.ARENA then
        if self.formationsIndex == 1 or self.formationsIndex == 2 then
            self.btnController:SetSelectedIndex(2)
        else
            self.btnController:SetSelectedIndex(0)
        end
    elseif self.formationType == EnumConst.FightTypeConst.FriendDefend then
        self.btnController:SetSelectedIndex(1)
    elseif self.formationType == EnumConst.FormationType.DarkStreet then
        self.btnController:SetSelectedIndex(3)
    elseif self.formationType == EnumConst.FormationType.PlunderBattle then
        self.btnController:SetSelectedIndex(1)
    elseif self.formationType == EnumConst.FormationType.FormationEditor then
        if FormationManager.IsInEditor() then
            self.btnController:SetSelectedIndex(1)
        end
    elseif self.formationType == EnumConst.FormationType.GuildBattlePlus then
        self.btnController:SetSelectedIndex(0)
        for i = self.formationsIndex + 1, self.formationsMax do
            if not (param.formationIsOver and param.formationIsOver[i]) then
                self.btnController:SetSelectedIndex(2)
                break ;
            end
        end
    elseif self.formationType == EnumConst.FormationType.StoryDuplicate or self.formationType == EnumConst.FormationType.DuplicateMore then
        self.btnController:SetSelectedIndex(0)
    else
        if self.formationsIndex < self.formationsMax then
            self.btnController:SetSelectedIndex(2)
        else
            self.btnController:SetSelectedIndex(0)
        end
    end
end

function UIBattleTeam:initBg()
    local mapId = logicMgr.MapManager.getMapId();
    --Util.SetPlayerPrefs("mapID", mapId);
    local current = self.stageConfig[tostring(mapId)];
    local bgId = current.f_MapType
    local mapIds = decodeJsonStrToTabel(G.dataTable["t_global"]["303"]["f_string_value"])
    for i = 1, #mapIds do
        if mapIds[i][1] == fightType then
            bgId = mapIds[i][2];
        end
    end
    --self.bgCtrl.selectedIndex = bgId;
    --
    --if current.f_NextStage ~= nil and current.f_NextStage > 0 then
    --    current = self.stageConfig[tostring(current.f_NextStage)];
    --    mapId = current.f_StageId;
    --end
    --self.bg:GetController("chapter").selectedIndex = current.f_ChapterId;
    --local stageNum = current.f_StageNum;
    --local maxIdxNum = math.ceil(logicMgr.MapManager.getMapStageNumById(mapId) / 4);
    --local idxNum = math.ceil(stageNum / 4);
    ----初始化关卡节点信息
    --for i = 1, maxIdxNum do
    --    local stepItem = self.bg:GetChild(tostring(i));
    --    local stateController = stepItem:GetController("type");
    --    if idxNum == i then
    --        stateController.selectedIndex = 1;
    --        stepItem:GetChild("text").text = current.f_ChapterId .. "-" .. current.f_StageNum;
    --    else
    --        if i == maxIdxNum then
    --            stateController.selectedIndex = 3;
    --        else
    --            if i < idxNum then
    --                stateController.selectedIndex = 0;
    --            elseif i > idxNum then
    --                stateController.selectedIndex = 2;
    --            end
    --        end
    --    end
    --end

end

function UIBattleTeam:onOpenSupSkillSelect(index)
    if fightType == EnumConst.FightTypeConst.RankBattle and logicMgr.RankBattleManager.BanPick() then
        return
    end
    if index == 0 then
        if FuncOpenManager.isOpen(Config.FuncOpenType.SupSkill, true, self.supSkillLeftBtn) then
            showUI(PanelNames.UISupSelect, nil, fightType, self.formationType, index);
        end
    else
        if FuncOpenManager.isOpen(Config.FuncOpenType.PetPartAttr, true, self.petSkill) then
            showUI(PanelNames.UISupSelect, nil, fightType, self.formationType, index);
        end
    end
end

function UIBattleTeam:freshPetSkill()
    if fightType ~= EnumConst.FightTypeConst.RankBattle and (not logicMgr.RankBattleManager.BanPick()) then
        local petskillId = logicMgr.SkillManager.getPetSkillIdByFormationType(self.formationType)
        if petskillId ~= 0 then
            self:freshIcon(self.petSkill, petskillId)
            self.petSkill:GetChild("n11").visible = false
        else
            self.petSkill:GetChild("n11").visible = true
        end
    else
        self.petSkill:GetChild("n11").visible = false
    end
end

function UIBattleTeam:freshIcon(obj, skillId)
    local data = G.dataTable["t_skillshow"][tostring(skillId)];
    if data then
        obj:GetChild("icon"):GetChild("icon").url = "ui://SkillAtlas/" .. data.f_SkillIcon;
    else
        obj:GetChild("icon"):GetChild("icon").url = ""
    end
end

function UIBattleTeam:refreshSupSkill()
    local self = UIBattleTeam;
    if fightType == EnumConst.FightTypeConst.RankBattle and logicMgr.RankBattleManager.BanPick() then
        self:freshIcon(self.supSkillLeftBtn, logicMgr.RankBattleManager.GetSupSkill())
        self:freshIcon(self.supSkillRight, logicMgr.RankBattleManager.GetEnemySupSkill())
        self:freshIcon(self.petRightSkill, logicMgr.RankBattleManager.GetEnemyPetSkill())
        self:freshIcon(self.petSkill, logicMgr.RankBattleManager.GetMyPetSkill())
        self.skillRedDots.visible = false
        return
    end
    local supSkills = logicMgr.SkillManager.getSupSkillInfo();
    if self.otherSupSkill then
        self:freshIcon(self.supSkillRight, self.otherSupSkill)
    end
    --if #supSkills == 0 then
    --    self.skillRedDots.visible = false;
    --end
    local isRedDot = false;

    if FormationManager.IsInEditor() then
        local index = FormationManager.GetFocus()
        local skill = FormationManager.GetTempSupskill(index)
        local petskillId = FormationManager.GetTempPetskill(index)
        if skill ~= 0 then
            self.battleInfo.helpSkillId = tostring(skill)
            self:freshIcon(self.supSkillLeftBtn, self.battleInfo.helpSkillId)
            self.skillRedDots.visible = false;
            isRedDot = false;
        else
            isRedDot = true;
        end
        self.petred.visible = false
        if petskillId ~= 0 then
            self:freshIcon(self.petSkill, petskillId)
        else
            if FuncOpenManager.isOpen(Config.FuncOpenType.PetPartAttr) then
                self.petred.visible = true
            end
        end
    else
        self.battleInfo.helpSkillId = logicMgr.SkillManager.getSupSkillIdByFormationType(self.formationType)
        if fightType == EnumConst.FightTypeConst.DUNGEON or fightType == EnumConst.FightTypeConst.StoryBattle then
            local data = logicMgr.BattlePlaybackManager.GetGroupBossHistory(self.formationsIndex);
            if data and data.record and data.record.win == 1 then
                self.battleInfo.helpSkillId = data.record.supportSkill
            end
        end
        if self.battleInfo.helpSkillId == nil or tonumber(self.battleInfo.helpSkillId) == 0 then
            dump(logicMgr.SkillManager.getSupSkillIdByFormationType(), "当前支援技数据")
            isRedDot = true;
        else
            local skillData = G.dataTable["t_skillshow"][tostring(self.battleInfo.helpSkillId)]
            if skillData then
                self.supSkillLeftBtn:GetChild("icon"):GetChild("icon").url = "ui://SkillAtlas/" .. skillData.f_SkillIcon;
            else
                logError("t_skillshow找不到技能 " .. tostring(self.battleInfo.helpSkillId))
            end
            self.skillRedDots.visible = false;
            isRedDot = false;
            m_current_show_skill = self.battleInfo.helpSkillId
        end
    end

    if not FuncOpenManager.isOpen(Config.FuncOpenType.SupSkill, false) then
        isRedDot = false;
    end
    self.skillRedDots.visible = isRedDot;
end

function UIBattleTeam:OnDisable()
    logicMgr.FuncOpenManager.removeStatusCtr(PanelNames.UIBattleTeam);

    if self.tableHeros then
        for i = 1, #self.tableHeros do
            logicMgr.HeroManager.setHeroState(self.tableHeros[i].partnerId, false, EnumConst.HeroHeadStateEnum.BATTLE, self.formationType, self.tableHeros[i]);
        end
    end
    self.isFriendBattle = nil
    self.playerIds = {}
    for i = 1, 3 do
        local count = table.getn(self.upBattleEffectForeObj[i]);
        for j = 1, count do
            local foreObj = table.remove(self.upBattleEffectForeObj[i]);
            local BackObj = table.remove(self.upBattleEffectBackObj[i]);
            if foreObj then
                destroyImmediate(foreObj)
            end
            if BackObj then
                destroyImmediate(BackObj)
            end
        end
    end
    self.upBattleEffectForeObj = {};
    self.upBattleEffectBackObj = {};
    local ctrlItem = CtrlManager.GetCtrl(PanelNames.TeamHeroItem);
    ctrlItem.onClear();
    ctrlItem.Destroy();
    self:LocalCloseEvent();
end

function UIBattleTeam:onClickType()
    self.curTabType = self:GetController("team").selectedIndex;
    for k, v in pairs(self.occupationBtns) do
        local occupationType = tonumber(string.split(v.name, "_")[2]) or -1;
        if self.curTabType == occupationType and v.grayed then
            UISysTips.AddMsg(getLanguage("ClimbTowerTips6"));
            self.teamController.selectedIndex = self.curTabIndex;
            return ;
        end
    end
    self.curTabIndex = self.curTabType or 0;    --记录上一次点击的type
    if self.curTabType > 0 then
        logicMgr.FriendBattleManager.IsClickType(true)
    end
    for k, v in pairs(self.tabHeroItem) do
        v.onClick:Clear();
    end
    self.tabOwner = {};

    for i = 1, #self.tableHeros do
        if self.tableHeros[i].type == self.curTabType or EnumConst.HeroTypeEnum.HeroTypeAll == self.curTabType then
            if self.formationType == EnumConst.FightTypeConst.RankBattle then
                --local item = logicMgr.HeroManager.copyHeroConfigbyModelId(self.tableHeros[i].parnterMdoelId)
                table.insert(self.tabOwner, self.tableHeros[i]);
            elseif fightType == EnumConst.FightTypeConst.TOWER then
                local curTowerType = logicMgr.TowerManager.getClimbType();
                --职业爬塔
                if G.dataTable["t_towertype"][tostring(curTowerType)].f_Group == EnumConst.TowerType.Advanced then
                    local canSelectHeroTypes = logicMgr.TowerManager.getAdvancedTowerHeroType(curTowerType)
                    for k, v in pairs(canSelectHeroTypes) do
                        if self.tableHeros[i].type == v and not self:isInFormations(self.tableHeros[i].partnerId, false) then
                            local item = logicMgr.HeroManager.getHeroDatabyPartnerId(self.tableHeros[i].partnerId);
                            table.insert(self.tabOwner, item);
                        end
                    end
                    self:AdvancedTowerDisableBtn()
                else
                    if not self:isInFormations(self.tableHeros[i].partnerId, false) then
                        local item = logicMgr.HeroManager.getHeroDatabyPartnerId(self.tableHeros[i].partnerId);
                        table.insert(self.tabOwner, item);
                    end
                end
            else
                if not self:isInFormations(self.tableHeros[i].partnerId, false) then
                    local item = nil;
                    if fightType == EnumConst.FightTypeConst.DarkStreet then
                        item = logicMgr.HeroManager.getHeroDatabyPartnerId(self.tableHeros[i].partnerId);
                        item["star"] = dataTable.getGlobalInt(661) or 150
                        if item["star"] > 0 then
                            item["quality"] = item["quality"] / 10
                        else
                            item["quality"] = 15
                        end
                    else
                        item = logicMgr.HeroManager.getHeroDatabyPartnerId(self.tableHeros[i].partnerId, true);
                    end
                    table.insert(self.tabOwner, item);
                end
            end
        end
    end
    if self.formationType ~= EnumConst.FightTypeConst.RankBattle then
        local sortFun = HeroManager.getSortHeroByType()
        table.sort(self.tabOwner, sortFun);
    end

    self.tabLeaseHero = {};
    for i = 1, #self.tableLeaseHeros do
        if self.tableLeaseHeros[i].type == self.curTabType or EnumConst.HeroTypeEnum.HeroTypeAll == self.curTabType then
            table.insert(self.tabLeaseHero, self.tableLeaseHeros[i]);
        end
    end

    self.Count = 0;
    self.index = 0;
    self.tableCount = 0;
    self.dynamicList.itemRenderer = function(index, obj)
        self:setData(index, obj);
    end
    self.tableCount = #self.tabLeaseHero;
    --local ownerCount = #self.tabOwner;
    self.dynamicList.numItems = (#self.tabOwner + self.tableCount);
    if self.curFightType == EnumConst.FightTypeConst.Expedition or self.curFightType == EnumConst.FightTypeConst.LongJourneyHell then
        self.dynamicList.lineGap = 30
    else
        self.dynamicList.lineGap = 5
    end
end

function UIBattleTeam.sortHero(a, b)
    if a["level"] > b["level"] then
        return true;
    elseif a["level"] == b["level"] then
        if a["star"] > b["star"] then
            return true;
        elseif a["star"] == b["star"] then
            return a["partnerModelId"] < b["partnerModelId"];
        else
            return false;
        end
    else
        return false;
    end
end
---@param itemobj GComponent
function UIBattleTeam:setData(index, itemobj)
    local self = UIBattleTeam;
    --itemobj.visible = false
    --utimer.timeCall(function ()
    --itemobj.visible = true
    index = index + 1;
    local itemValue;
    if index > self.tableCount then
        index = index - self.tableCount;
        itemValue = self.tabOwner[index];
    else
        itemValue = self.tabLeaseHero[index];
    end
    local go = itemobj;
    local localModelId = itemValue["partnerModelId"];
    if self.tabLeaseAndOwnerHeros[localModelId] ~= nil then
        if itemValue["leaseHero"] ~= nil then
            self.tabLeaseAndOwnerHeros[localModelId].leaseItemGo = go;
        else
            self.tabLeaseAndOwnerHeros[localModelId].ownerItemGo = go;
        end
    end
    local type = self.isShowTitle and 1 or 0;
    itemobj:SetScale(1, 1)
    local charactor = CtrlManager.GetCtrl(PanelNames.HeadRectItem);
    --local ctrl = itemobj:GetTransition("Effect_List")
    --ctrl:Play()
    if charactor ~= nil then
        --初始英雄信息
        if itemValue then
            charactor.initData(go, itemValue, nil, fightType, nil, nil, nil, nil, nil, self.formationType);
            charactor.updateDecTitle(go, itemValue, type, nil, fightType, self.formationType);
            charactor.updateDebris(go, itemValue, self.isShowDebris, nil, fightType, self.formationType)
        end
    end
    self.Count = self.Count + 1;
    --go.onClick:Clear();
    --go.onClick:Add(function()
    --    HeroManager.HeroPlayCV(itemValue["partnerModelId"], EnumConst.HeroActionType.GoBattleTeame);
    --    self:onClickHero(itemValue, go);
    --end);
    go.onTouchBegin:Clear();
    go.onTouchEnd:Clear();
    --go.onTouchMove:Clear();
    go.onTouchBegin:Add(function(evt)
        self:OnTouchStart(evt, itemValue);
    end)
    go.onTouchMove:Add(function(evt)
        self:OnTouchMove(evt);
    end)
    go.onTouchEnd:Add(function()
        self:OnTouchUp(itemValue, go);
    end)
    go.displayObject.gameObject.name = "card" .. index;
    if itemValue then
        self.tabHeroItem[itemValue["partnerId"]] = go;
        if self.curFightType == EnumConst.FightTypeConst.Expedition then
            local expeditionInfo = logicMgr.ExpeditionMgr.GetHeroInfo(itemValue["partnerId"])
            if expeditionInfo then
                charactor.UpdateHPMPBar(itemobj, expeditionInfo.hp, expeditionInfo.energy)
            else
                charactor.UpdateHPMPBar(itemobj, 100, 100)
            end
        elseif self.curFightType == EnumConst.FightTypeConst.GuildBattlePlus and logicMgr.GuildBattlePlusManager.getNowType() == EnumConst.GuildBattlePlusType.Territory then
            charactor.UpdateCostPower(itemobj, logicMgr.GuildBattlePlusManager.getCostPowerMaxByType(), logicMgr.GuildBattlePlusManager.getCostPowerExpendByType(), logicMgr.GuildBattlePlusManager.getHeroPowerById(itemValue.partnerId))
        elseif self.curFightType == EnumConst.FightTypeConst.LongJourneyHell then
            local longJourneyMemberData = logicMgr.LongJourneyHellManager.getMemberList(itemValue["partnerId"]);
            charactor.UpdateHPMPBar(itemobj, longJourneyMemberData.hpRate, longJourneyMemberData.mpRate)
        end
    end
    --end,100*index,1)
end

function UIBattleTeam:OnTouchStart(evt, heroData)
    self.lastEventX = evt.inputEvent.x;
    self.lastEventY = evt.inputEvent.y;
    self.isTouching = true;
    self.timerId = utimer.timeCall(function()
        self.timerId = nil;
        if self.curFightType == EnumConst.FightTypeConst.GuildBattlePlus then
            return ;
        end
        local flag = true;
        for k, v in pairs(logicMgr.BattlePlaybackManager.GetGroupBossHistory()) do
            flag = false
        end
        if flag then
            if fightType ~= EnumConst.FightTypeConst.RankBattle and heroData["leaseHero"] == nil then
                self.isNotNeedEnable = true;
                --self.fguiObj.visible = false;
                if self.isFriendBattle then
                    closeUI(PanelNames.UITeam)
                end
                showUI(PanelNames.UICharactorInfoHero, heroData, nil, true, function()
                    self:updateAllHeroData()
                end, nil, function()
                    self:onClickBack1();
                end);
            end
        else
            UISysTips.AddMsg("该场战斗已经打响，不能进行英雄养成");
        end
    end, 500, 1);
end

function UIBattleTeam:OnTouchMove(evt)
    if self.timerId ~= nil then
        if math.abs(self.lastEventY - evt.inputEvent.y) > 20 or math.abs(self.lastEventX - evt.inputEvent.x) > 20 then
            utimer.remove(self.timerId);
            self.timerId = nil;
            self.isTouching = false;
        end
    end
end

function UIBattleTeam:OnTouchUp(itemValue, go)
    if self.timerId ~= nil and self.isTouching then
        utimer.remove(self.timerId);
        self.timerId = nil;
        if self.curFightType == EnumConst.FightTypeConst.GuildBattlePlus and logicMgr.GuildBattlePlusManager.getNowType() == EnumConst.GuildBattlePlusType.Territory then
            if not param.isIgnorePower and logicMgr.GuildBattlePlusManager.getCostPowerExpendByType() > logicMgr.GuildBattlePlusManager.getHeroPowerById(itemValue.partnerId) then
                UISysTips.AddMsg("体力不足，无法上阵");
                return ;
            end
        end
        if self.clearController.selectedIndex == 0 then
            --上阵
            local battle = false
            for i = 1, nodeCount do
                if self.tabHeroPosData[i] ~= nil and self.tabHeroPosData[i]["partnerId"] == itemValue.partnerId then
                    battle = true
                    break
                end
            end

            if not battle then
                --下阵不播
                AudioManager.PlayInteractionVoice(itemValue["partnerModelId"], 0, AudioManager.InteractionTagTable[16].Tag)
            end

            self:onClickHero(itemValue, go);
        end
    end
end

function UIBattleTeam:updateAllHeroData()
    if HelperFunc.IsNull(self.fguiObj) then
        closeUI(PanelNames.UIBattleTeam)
        return
    end
    --self.fguiObj.visible = true
    self.tableHeros = logicMgr.HeroManager.getOwnerHeroList(false);
    for i = 1, #self.tableHeros do
        local localModelId = self.tableHeros[i]["partnerModelId"];
        if self.tabLeaseAndOwnerHeroIndex[localModelId] ~= nil then
            self.tabLeaseAndOwnerHeroIndex[localModelId].ownerIndex = i;
        end
    end
    self:onClickType()
    self:initFormation()
    self:rendererFormation()
    if self.isFriendBattle then
        showUI(PanelNames.UITeam)
    end
    self.isNotNeedEnable = false;
end

function UIBattleTeam:onClickHero(heroData, go)
    if self.formationType == EnumConst.FightTypeConst.RankBattle and heroData then
        if logicMgr.RankBattleManager.BanPick() then
            local bpChooseHero = decodeJsonStrToTabel(G.dataTable["t_global"]["223"].f_string_value)
            local bpindex = logicMgr.RankBattleManager.GetBPIndex()
            local bplength = logicMgr.RankBattleManager.GetFormationLength()
            local count = 0
            for _, v in ipairs(self.tabHeroPosData) do
                if v.partnerModelId and v.partnerModelId ~= 0 then
                    count = count + 1
                end
            end
            local helpId = self.helpMan[self.formationsIndex]["partnerModelId"]
            if helpId and helpId ~= 0 then
                count = count + 1
            end
            if not (ZZMathBit.andOp(heroData.state, EnumConst.HeroHeadStateEnum.ASSIST) > 0 or ZZMathBit.andOp(heroData.state, EnumConst.HeroHeadStateEnum.BATTLE) > 0) then
                count = count + 1
            end
            if count - bplength > bpChooseHero[bpindex] then
                UISysTips.AddMsg("本轮选择英雄数量超过上限")
                return
            end
            if logicMgr.RankBattleManager.BPCanChooseHeroByModelId(heroData.partnerModelId) then
                UISysTips.AddMsg("该英雄已被选择")
                return
            end
        end
        if logicMgr.RankBattleManager.IsBan(heroData.partnerModelId) then
            UISysTips.AddMsg(getLanguage("ErrorCode_180006"))
            return
        end
        if logicMgr.HeroManager.NotHaveByModeId(heroData.partnerModelId) then
            local num = logicMgr.RankBattleManager.HeroUsed(heroData.partnerModelId)
            local max = G.dataTable["t_global"]["221"].f_int_value
            if num then
                if num >= max then
                    UISysTips.AddMsg(getLanguage("ErrorCode_180002"))
                    return
                end
            end
        end
    end
    if ZZMathBit.andOp(heroData["state"], EnumConst.HeroHeadStateEnum.USED) > 0 then
        UISysTips.AddMsg(getLanguage("ErrorCode_210005"));
        return ;
    end
    local isOwner = true;
    local curModelHeroId = heroData["partnerModelId"];
    local hero = logicMgr.HeroManager.getHeroDatabyPartnerId(heroData["partnerId"], true);
    if hero == nil then
        isOwner = false;
    end
    if not hero and (fightType == EnumConst.FightTypeConst.RankBattle or fightType == EnumConst.FightTypeConst.Plunder or fightType == EnumConst.FightTypeConst.DUNGEON) then
        hero = heroData
    end
    if hero ~= nil then
        if ZZMathBit.andOp(hero.state, EnumConst.HeroHeadStateEnum.DEAD) > 0 then
            UISysTips.AddMsg(getLanguage("UIBattleTeam_State_Dead_Tip"))
            return
        end
        if self:CanTeam(heroData["partnerModelId"]) then
            return
        end
        if not self.isChangTeam then
            self.lastHelpManId = self.helpMan[self.formationsIndex].partnerModelId;
        end

        self.lastFormationPosData = clone(self.tabHeroPosData) or {}
        if ZZMathBit.andOp(hero.state, EnumConst.HeroHeadStateEnum.ASSIST) > 0 or ZZMathBit.andOp(hero.state, EnumConst.HeroHeadStateEnum.BATTLE) > 0 then
            local data;
            if self.helpMan[self.formationsIndex] ~= nil and tostring(self.helpManId[self.formationsIndex]) == tostring(heroData["partnerId"]) then
                data = logicMgr.HeroManager.setHeroState(heroData["partnerId"], false, EnumConst.HeroHeadStateEnum.BATTLE, self.formationType, hero);
                self.helpManId[self.formationsIndex] = "0"
                self.helpMan[self.formationsIndex]["partnerId"] = nil;
                self.helpMan[self.formationsIndex]["partnerModelId"] = nil;
                self.helpMan[self.formationsIndex]["icon"] = "";
                self.helpMan[self.formationsIndex]["type"] = nil;
                self.helpMan[self.formationsIndex]["power"] = nil;
                self.helpMan[self.formationsIndex]["realPower"] = nil;
                self.helpMan[self.formationsIndex]["state"] = 0;
                self.helpMan[self.formationsIndex]["weaponRank"] = nil
                self.formations[self.formationsIndex][6] = "0"
                heroData["state"] = 0;
            else
                for i = 1, #self.tabHeroPosData do
                    if self.tabHeroPosData[i] ~= nil and self.tabHeroPosData[i]["partnerId"] == heroData["partnerId"] then
                        data = logicMgr.HeroManager.setHeroState(heroData["partnerId"], false, EnumConst.HeroHeadStateEnum.BATTLE, self.formationType, hero);
                        self.tabHeroPosData[i]["partnerId"] = nil;
                        self.tabHeroPosData[i]["partnerModelId"] = nil;
                        self.tabHeroPosData[i]["icon"] = "";
                        self.tabHeroPosData[i]["type"] = nil;
                        self.tabHeroPosData[i]["power"] = nil;
                        self.tabHeroPosData[i]["realPower"] = nil;
                        self.formations[self.formationsIndex][i] = "0"
                        self.tabHeroPosData[i]["state"] = 0;
                        self.tabHeroPosData[i]["weaponRank"] = nil;
                        heroData["state"] = 0;
                        break ;
                    end
                end
            end
            if fightType == EnumConst.FightTypeConst.DUNGEON then
                if data ~= nil then
                    local saveGo = self.tabLeaseAndOwnerHeros[curModelHeroId];
                    local saveIndex = self.tabLeaseAndOwnerHeroIndex[curModelHeroId];
                    local ctrlItem = CtrlManager.GetCtrl(PanelNames.HeadRectItem);
                    if isOwner then
                        -- 是自己
                        if ctrlItem ~= nil then
                            ctrlItem.updateState(go, data);
                        end
                        if saveGo ~= nil and saveIndex ~= nil then
                            local leaseHero = self.tableLeaseHeros[saveIndex.leaseIndex];
                            if leaseHero ~= nil then
                                leaseHero["state"] = 0;
                                if ctrlItem ~= nil then
                                    ctrlItem.updateState(saveGo.leaseItemGo, leaseHero);
                                end
                            end
                        end
                    else
                        -- 不是自己
                        if data["leaseHero"] ~= nil then
                            if ctrlItem ~= nil then
                                ctrlItem.updateState(go, data);
                            end
                            if saveGo ~= nil and saveIndex ~= nil then
                                local leaseHero = self.tableHeros[saveIndex.ownerIndex];
                                if leaseHero ~= nil then
                                    data = logicMgr.HeroManager.setHeroState(leaseHero["partnerId"], false, EnumConst.HeroHeadStateEnum.USED, self.formationType, leaseHero);
                                    if data ~= nil then
                                        if ctrlItem ~= nil then
                                            ctrlItem.updateState(saveGo.ownerItemGo, data);
                                        end
                                    end
                                end
                            end
                        else
                            if saveGo ~= nil and saveIndex ~= nil then
                                local leaseHero = self.tableLeaseHeros[saveIndex.leaseIndex];
                                if leaseHero ~= nil then
                                    leaseHero["state"] = 0;
                                    if ctrlItem ~= nil then
                                        ctrlItem.updateState(saveGo.leaseItemGo, leaseHero);
                                    end
                                end
                                leaseHero = self.tableHeros[saveIndex.ownerIndex];
                                if leaseHero ~= nil then
                                    data = logicMgr.HeroManager.setHeroState(leaseHero["partnerId"], false, EnumConst.HeroHeadStateEnum.USED, self.formationType, leaseHero);
                                    if data ~= nil then
                                        if ctrlItem ~= nil then
                                            ctrlItem.updateState(saveGo.ownerItemGo, data);
                                        end
                                    end
                                end
                            end
                        end
                    end
                    if self.isFriendBattle then
                        logicMgr.FriendBattleManager.BattleTeam(self.tabHeroPosData, self.helpMan[self.formationsIndex])
                        FireEvent(Config.EventType.FreshBorrowTeam, self.playerIds)
                    end
                    self:rendererFormation();
                end
            else
                if data ~= nil then
                    local ctrlItem = CtrlManager.GetCtrl(PanelNames.HeadRectItem);
                    if ctrlItem ~= nil then
                        ctrlItem.updateState(go, data);
                    end
                    if self.isFriendBattle then
                        logicMgr.FriendBattleManager.BattleTeam(self.tabHeroPosData, self.helpMan[self.formationsIndex])
                        FireEvent(Config.EventType.FreshBorrowTeam, self.playerIds)
                    end
                    self:rendererFormation();
                end
            end
        else
            local bFull = true;
            local data
            if self:CanTeam(heroData["partnerModelId"]) then
                return
            end
            for i = 1, #self.tabHeroPosData do
                if i ~= 6 and self.tabHeroPosData[i] ~= nil and self.tabHeroPosData[i]["partnerId"] == nil then
                    bFull = false;
                    break ;
                end
            end
            if bFull then
                if self.helpMan[self.formationsIndex] ~= nil and self.helpMan[self.formationsIndex]["partnerId"] == nil and logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HelpMan, true) then
                    if not self.isChangTeam then
                        self.lastHelpManId = self.helpMan[self.formationsIndex].partnerModelId;
                    end
                    self.lastFormationPosData = clone(self.tabHeroPosData) or {}
                    data = logicMgr.HeroManager.setHeroState(heroData["partnerId"], true, EnumConst.HeroHeadStateEnum.BATTLE, self.formationType, hero);
                    self.helpMan[self.formationsIndex]["partnerId"] = heroData["partnerId"];
                    self.helpManId[self.formationsIndex] = tostring(heroData["partnerId"]) or "0";
                    self.helpMan[self.formationsIndex]["partnerModelId"] = heroData["partnerModelId"];
                    self.helpMan[self.formationsIndex]["level"] = heroData["level"];
                    self.helpMan[self.formationsIndex]["star"] = heroData["star"];
                    self.helpMan[self.formationsIndex]["weaponLevel"] = heroData["weaponLevel"];
                    self.helpMan[self.formationsIndex]["type"] = heroData["type"];
                    self.helpMan[self.formationsIndex]["power"] = heroData["power"];
                    self.helpMan[self.formationsIndex]["realPower"] = heroData["realPower"];
                    self.helpMan[self.formationsIndex]["state"] = data["state"];
                    self.helpMan[self.formationsIndex]["weaponRank"] = logicMgr.HeroManager.GetWeaponQuality(heroData["partnerModelId"])
                    self.formations[self.formationsIndex][6] = tostring(heroData["partnerId"]) or "0";
                else
                    UISysTips.AddMsg(getLanguage("Character_Tips1"));
                    return ;
                end
            else
                if self:CanTeam(heroData["partnerModelId"]) then
                    return
                end
                self.lastFormationPosData = clone(self.tabHeroPosData) or {}
                for i = 1, #self.tabHeroPosData do
                    if self.tabHeroPosData[i] ~= nil and self.tabHeroPosData[i]["partnerId"] == nil then
                        data = logicMgr.HeroManager.setHeroState(heroData["partnerId"], true, EnumConst.HeroHeadStateEnum.BATTLE, self.formationType, hero);
                        self.tabHeroPosData[i]["partnerId"] = heroData["partnerId"];
                        self.tabHeroPosData[i]["partnerModelId"] = heroData["partnerModelId"];
                        self.tabHeroPosData[i]["level"] = heroData["level"];
                        self.tabHeroPosData[i]["star"] = heroData["star"];
                        self.tabHeroPosData[i]["weaponLevel"] = heroData["weaponLevel"];
                        self.tabHeroPosData[i]["type"] = heroData["type"];
                        self.tabHeroPosData[i]["power"] = heroData["power"];
                        self.tabHeroPosData[i]["realPower"] = heroData["realPower"];
                        self.formations[self.formationsIndex][i] = heroData["partnerId"];
                        self.tabHeroPosData[i]["state"] = heroData["state"];
                        self.tabHeroPosData[i]["weaponRank"] = logicMgr.HeroManager.GetWeaponQuality(heroData["partnerModelId"])
                        if self.isFriendBattle then
                            self.clickIndex = i;
                            FireEvent(Config.EventType.BattleTeamClickIndex, self.clickIndex)
                        end
                        self:checkRestrain(self.tabHeroPosData[i]["partnerModelId"], i)
                        break ;
                    end
                end
            end
            local ctrlItem = CtrlManager.GetCtrl(PanelNames.HeadRectItem);
            if fightType == EnumConst.FightTypeConst.DUNGEON then
                if data ~= nil then
                    local saveGo = self.tabLeaseAndOwnerHeros[data.partnerModelId];
                    local saveIndex = self.tabLeaseAndOwnerHeroIndex[data.partnerModelId];
                    if isOwner then
                        -- 是自己
                        if ctrlItem ~= nil then
                            ctrlItem.updateState(go, data);
                        end
                        if saveGo ~= nil and saveIndex ~= nil then
                            local leaseHero = self.tableLeaseHeros[saveIndex.leaseIndex];
                            if leaseHero ~= nil then
                                leaseHero["state"] = 2;
                                if ctrlItem ~= nil then
                                    ctrlItem.updateState(saveGo.leaseItemGo, leaseHero);
                                end
                            end
                        end
                    else
                        -- 不是自己
                        if data["leaseHero"] ~= nil then
                            if ctrlItem ~= nil then
                                ctrlItem.updateState(go, data);
                            end
                            if saveGo ~= nil and saveIndex ~= nil then
                                local leaseHero = self.tableHeros[saveIndex.ownerIndex];
                                if leaseHero ~= nil then
                                    data = logicMgr.HeroManager.setHeroState(leaseHero["partnerId"], true, EnumConst.HeroHeadStateEnum.USED, self.formationType, leaseHero);
                                    if data ~= nil then
                                        if ctrlItem ~= nil then
                                            ctrlItem.updateState(saveGo.ownerItemGo, data);
                                        end
                                    end
                                end
                            end
                        else
                            if saveGo ~= nil and saveIndex ~= nil then
                                local leaseHero = self.tableLeaseHeros[saveIndex.leaseIndex];
                                if leaseHero ~= nil then
                                    leaseHero["state"] = 4;
                                    if ctrlItem ~= nil then
                                        ctrlItem.updateState(saveGo.leaseItemGo, leaseHero);
                                    end
                                end
                                leaseHero = self.tableHeros[saveIndex.ownerIndex];
                                if leaseHero ~= nil then
                                    data = logicMgr.HeroManager.setHeroState(leaseHero["partnerId"], true, EnumConst.HeroHeadStateEnum.USED, self.formationType, leaseHero);
                                    if data ~= nil and ctrlItem ~= nil then
                                        ctrlItem.updateState(saveGo.ownerItemGo, data);
                                    end
                                end
                            end
                        end
                    end
                end
            else
                if data ~= nil then
                    if ctrlItem ~= nil then
                        ctrlItem.updateState(go, data);
                    end
                end
            end
            if self.isFriendBattle then
                logicMgr.FriendBattleManager.BattleTeam(self.tabHeroPosData, self.helpMan[self.formationsIndex])
                FireEvent(Config.EventType.FreshBorrowTeam, self.playerIds)
            end
            self:rendererFormation();
        end
        self:refreshCombinationSkill();
    end
end

-- 检查并播放克制关系
function UIBattleTeam:checkRestrain(partnerModelId, index)
    if index > #self._counterpointList or partnerModelId == nil then
        return ;
    end
    if self.oppoFormations[self.formationsIndex] then
        if self.oppoFormations[self.formationsIndex][self._counterpointList[index]] then
            if logicMgr.HeroManager.GetHeroRestrain(partnerModelId, self.oppoFormations[self.formationsIndex][self._counterpointList[index]]["partnerModelId"]) then
                self:playRestrain(index, 1);
            end
        end
        for k, v in pairs(self.oppoFormations[self.formationsIndex]) do
            if v.partnerModelId ~= nil and self._counterpointList[k] == index and logicMgr.HeroManager.GetHeroRestrain(v.partnerModelId, partnerModelId) then
                self:playRestrain(k, 2);
            end
        end
    end
end

-- 播放克制关系 type=1 我方克制敌方,type=2 敌方克制我方,
function UIBattleTeam:playRestrain(index, type)
    if index > #self.restrainObjList[type] then
        return ;
    end
    if self.playRestrainTimeList[type][index] then
        utimer.remove(self.playRestrainTimeList[type][index]);
    end
    self.restrainObjList[type][index].visible = true;
    self.restrainObjList[type][index].alpha = 1;
    local xx = self._restrainTime;
    self.playRestrainTimeList[type][index] = utimer.frameCall(function()
        xx = xx - 100;
        if xx <= 0 then
            self.restrainObjList[type][index].visible = false;
            self.playRestrainTimeList[type][index] = nil;
            return true;
        end
        self.restrainObjList[type][index].alpha = xx / self._restrainTime;
    end, 100, -1);
end

function UIBattleTeam:CanTeam(partnerModelId)
    local isTip = nil
    if self.isFriendBattle then
        local ismy, index = logicMgr.FriendBattleManager.IsGoBattle(partnerModelId)
        if ismy and self.playerIds[index] and tonumber(tostring(self.playerIds[index])) ~= 0 then
            UISysTips.AddMsg("不能上阵相同的英雄")
            isTip = true
        end
    end
    return isTip
end

function UIBattleTeam:BorrowInfo(msg)
    local self = UIBattleTeam;
    local i = nil;
    local ishave
    for k, v in ipairs(self.tabHeroPosData) do
        if v and v["partnerId"] == nil then
            i = k
            break
        end
    end
    if not i then
        if not self.helpMan[self.formationsIndex] then
            i = 6
        end
    end
    for k, v in ipairs(self.tabHeroPosData) do
        if v.partnerModelId == msg.partnerModelId and self.playerIds[k] ~= 0 then
            ishave = true
            i = k
            break
        end
    end
    if self.helpMan[self.formationsIndex] and tonumber(self.helpMan[self.formationsIndex].partnerModelId) == tonumber(msg.partnerModelId) and self.playerIds[6] ~= 0 then
        ishave = true
        i = 6
    end
    if i then
        self.lastFormationPosData = clone(self.tabHeroPosData) or {}
        if not self.isChangTeam then
            self.lastHelpManId = self.helpMan[self.formationsIndex].partnerModelId;
        end

        if i < 6 then
            if self.tabHeroPosData[i] ~= nil and self.tabHeroPosData[i]["partnerId"] == nil and (not ishave) then
                self.tabHeroPosData[i]["partnerId"] = msg.partnerId
                self.tabHeroPosData[i]["partnerModelId"] = msg.partnerModelId
                self.tabHeroPosData[i]["level"] = msg.level
                self.tabHeroPosData[i]["power"] = msg.power
                self.tabHeroPosData[i]["realPower"] = 0
                self.tabHeroPosData[i]["star"] = msg.star
                self.tabHeroPosData[i]["name"] = msg.name
                self.tabHeroPosData[i]["type"] = logicMgr.HeroManager.getHeroDatabyModelId(msg.partnerModelId)["type"]
                self.tabHeroPosData[i]["weaponRank"] = msg.weaponRank
                self.formations[self.formationsIndex][i] = msg.partnerId
                self.playerIds[i] = msg.playerId
            else
                self.tabHeroPosData[i]["partnerId"] = nil;
                self.tabHeroPosData[i]["partnerModelId"] = nil;
                self.tabHeroPosData[i]["type"] = nil;
                self.formations[self.formationsIndex][i] = 0;
                self.tabHeroPosData[i]["power"] = nil
                self.tabHeroPosData[i]["realPower"] = nil
                self.tabHeroPosData[i]["star"] = nil
                self.tabHeroPosData[i]["name"] = nil
                self.tabHeroPosData[i]["weaponRank"] = nil
                self.playerIds[i] = nil
            end
        else
            if self.helpMan[self.formationsIndex] ~= nil and tonumber(self.lastHelpManId) == tonumber(msg.partnerModelId) and ishave then
                self.helpManId[self.formationsIndex] = "0"
                self.helpMan[self.formationsIndex]["partnerId"] = nil;
                self.helpMan[self.formationsIndex]["partnerModelId"] = nil;
                self.helpMan[self.formationsIndex]["type"] = nil;
                self.helpMan[self.formationsIndex]["power"] = nil;
                self.helpMan[self.formationsIndex]["realPower"] = nil;
                self.helpMan[self.formationsIndex]["star"] = nil
                self.helpMan[self.formationsIndex]["name"] = nil
                self.helpMan[self.formationsIndex]["weaponRank"] = nil
                self.playerIds[i] = nil
            else
                self.helpMan[self.formationsIndex]["partnerId"] = msg.partnerId;
                self.helpManId[self.formationsIndex] = tostring(msg.partnerId);
                self.helpMan[self.formationsIndex]["level"] = msg.level;
                self.helpMan[self.formationsIndex]["star"] = msg.star
                self.helpMan[self.formationsIndex]["weaponLevel"] = msg.weaponLevel
                self.helpMan[self.formationsIndex]["partnerModelId"] = msg.partnerModelId;
                self.helpMan[self.formationsIndex]["name"] = msg.name;
                self.helpMan[self.formationsIndex]["type"] = logicMgr.HeroManager.getHeroDatabyModelId(msg.partnerModelId, true)["type"];
                self.playerIds[i] = msg.playerId
                self.helpMan[self.formationsIndex]["power"] = msg.power
                self.helpMan[self.formationsIndex]["realPower"] = 0
                self.helpMan[self.formationsIndex]["weaponRank"] = msg.weaponRank
            end
        end
        logicMgr.FriendBattleManager.BattleTeam(self.tabHeroPosData, self.helpMan[self.formationsIndex])
        FireEvent(Config.EventType.FreshBorrowTeam, self.playerIds)
        self:rendererFormation();
    else
        UISysTips.AddMsg("上阵英雄已达到上限")
        return
    end
end

function UIBattleTeam:changePosByIndex(idx1, idx2)
    local tempIdx;
    --self.lastHelpManId = self.helpMan[self.formationsIndex].partnerModelId;
    --self.lastFormationPosData = clone(self.tabHeroPosData) or {}
    if idx2 ~= idx1 then
        if idx2 >= nodeCount + 1 then
            if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HelpMan, true) then
                tempIdx = self.formations[self.formationsIndex][idx1]
                self.formations[self.formationsIndex][idx1] = self.helpManId[self.formationsIndex] or "0";
                if tempIdx == nil or tempIdx == "" then
                    tempIdx = "0";
                end
                self.helpManId[self.formationsIndex] = tostring(tempIdx);
                self:checkRestrain(self.tabHeroPosDataTemp[self.formationsIndex][idx1]["partnerModelId"], idx2)
                self:checkRestrain(self.helpMan[self.formationsIndex]["partnerModelId"], idx1)
            else
                return
            end
        elseif idx1 >= nodeCount + 1 then
            if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HelpMan, true) then
                tempIdx = self.formations[self.formationsIndex][idx2]
                self.formations[self.formationsIndex][idx2] = self.helpManId[self.formationsIndex] or "0";
                if tempIdx == nil or tempIdx == "" then
                    tempIdx = "0";
                end
                self.helpManId[self.formationsIndex] = tostring(tempIdx);
                self:checkRestrain(self.tabHeroPosDataTemp[self.formationsIndex][idx2]["partnerModelId"], idx1)
                self:checkRestrain(self.helpMan[self.formationsIndex]["partnerModelId"], idx2)
            else
                return
            end
        else
            tempIdx = self.formations[self.formationsIndex][idx1]
            self.formations[self.formationsIndex][idx1] = self.formations[self.formationsIndex][idx2];
            self.formations[self.formationsIndex][idx2] = tempIdx;
            self:checkRestrain(self.tabHeroPosDataTemp[self.formationsIndex][idx1]["partnerModelId"], idx2)
            self:checkRestrain(self.tabHeroPosDataTemp[self.formationsIndex][idx2]["partnerModelId"], idx1)
        end
        if self.isFriendBattle then
            local temp = self.playerIds[idx1]
            local temp2 = self.tabHeroPosData[idx1]
            if idx1 >= 6 then
                temp2 = self.helpMan[self.formationsIndex]
            end
            if self.playerIds[idx1] or self.playerIds[idx2] then
                self.playerIds[idx1] = self.playerIds[idx2]
                self.playerIds[idx2] = temp
                if idx1 >= 6 then
                    self.helpMan[self.formationsIndex] = self.tabHeroPosData[idx2]
                    self.tabHeroPosData[idx2] = temp2
                elseif idx2 >= 6 then
                    self.tabHeroPosData[idx1] = self.helpMan[self.formationsIndex]
                    self.helpMan[self.formationsIndex] = temp2
                else
                    self.tabHeroPosData[idx1] = self.tabHeroPosData[idx2]
                    self.tabHeroPosData[idx2] = temp2
                end
            end
        end
        if idx1 <= nodeCount then
            self:checkRestrain(self.tabHeroPosDataTemp[self.formationsIndex][idx1]["partnerModelId"], idx2)
        end
        if idx2 <= nodeCount then
            self:checkRestrain(self.tabHeroPosDataTemp[self.formationsIndex][idx2]["partnerModelId"], idx1)
        end
    end
    self:initFormation()
    self:rendererFormation()
    self:refreshCombinationSkill();
end

function UIBattleTeam:setSelfFormationByType(fightType, param)
    --- 获取我方阵容
    self.formations = {}
    if fightType == nil then
        return
    end
    self.formationType = nil

    if fightType == EnumConst.FightTypeConst.DUNGEON and self.formationsMax <= 1 then
        self.formationType = EnumConst.FormationType.Duplicate;
    elseif fightType == EnumConst.FightTypeConst.DUNGEON and self.formationsMax > 1 then
        self.formationType = EnumConst.FormationType.DuplicateMore;
    elseif fightType == EnumConst.FightTypeConst.INSTANCE then
        self.formationType = EnumConst.FormationType.MythicDungeons;
    elseif fightType == EnumConst.FightTypeConst.TOWER then
        local curTowerType = logicMgr.TowerManager.getClimbType();
        self.formationType = G.dataTable["t_towertype"][tostring(curTowerType)]["f_FormationType"];
    elseif fightType == EnumConst.FightTypeConst.ARENA then
        self.formationType = param.type;
        if self.formationType == EnumConst.FormationType.ArenaAtk then
            self:RefreshSkipState()
        end
    elseif fightType == EnumConst.FightTypeConst.ARENARECORD then
        if type(param) == "table" and param.arena_type then
            if param.arena_type == EnumConst.ArenaBattleType.Cross then
                self.formationType = EnumConst.FormationType.CrossArenaAtk
            elseif param.arena_type == EnumConst.ArenaBattleType.TeamCross then
                self.formationType = EnumConst.FormationType.TeamCrossArenaAtk
            else
                self.formationType = EnumConst.FormationType.ArenaAtk
            end
        else
            self.formationType = EnumConst.FormationType.ArenaAtk
        end
    elseif fightType == EnumConst.FightTypeConst.Expedition then
        self.formationType = EnumConst.FormationType.Expedition
    elseif fightType == EnumConst.FightTypeConst.TRIAL then
        self.formationType = EnumConst.FormationType.TrialsChaos
    elseif fightType == EnumConst.FightTypeConst.FriendAttack then
        self.formationType = EnumConst.FormationType.FriendAttack
    elseif fightType == EnumConst.FightTypeConst.FriendDefend then
        self.formationType = EnumConst.FormationType.FriendDefend
    elseif fightType == EnumConst.FightTypeConst.RankBattle then
        self.formationType = EnumConst.FormationType.RankBattle
    elseif fightType == EnumConst.FightTypeConst.FriendCompeteBattle or fightType == EnumConst.FightTypeConst.GuildFriendCompeteBattle then
        self.formationType = EnumConst.FormationType.FriendCompeteBattle
    elseif fightType == EnumConst.FightTypeConst.Plunder then
        self.formationType = param.type
    elseif fightType == EnumConst.FightTypeConst.DarkStreet then
        self.formationType = EnumConst.FormationType.DarkStreet
    elseif fightType == EnumConst.FightTypeConst.GuildBattlePlus then
        self.formationType = EnumConst.FormationType.GuildBattlePlus
    elseif fightType == EnumConst.FightTypeConst.FormationEditor then
        self.formationType = EnumConst.FormationType.FormationEditor
    elseif fightType == EnumConst.FightTypeConst.DungeonEventPK then
        self.formationType = EnumConst.FormationType.DungeonEventPK
    elseif fightType == EnumConst.FightTypeConst.SoloChaosTest then
        self.formationType = EnumConst.FormationType.SoloChaosTest
    elseif fightType == EnumConst.FightTypeConst.StoryBattle then
        self.formationType = EnumConst.FormationType.StoryDuplicate
        self:RefreshSkipState()

    elseif fightType == EnumConst.FightTypeConst.LongJourneyHell then
        self.formationType = EnumConst.FormationType.LongJourneyHell
    end

    if self.formationType == nil then
        return
    end
    SUPPORT_TEAMMATE_SITE = 6
    nodeCount = 5
    --[[if fightType == EnumConst.FightTypeConst.ARENA then
        if self.formationType == 3 or self.formationType == 4 then
            SUPPORT_TEAMMATE_SITE = 8
            nodeCount = 7
        end
    end--]]

    local defaultFormation
    if self.formationType == EnumConst.FormationType.FormationEditor then
        local index = logicMgr.FormationManager.GetFocus()
        local tb = logicMgr.FormationManager.GetEditorTeam(index, true)
        if tb then
            defaultFormation = tb.team
        end
    else
        defaultFormation = logicMgr.FormationManager.GetFormation(self.formationType);
    end

    -- local defaultFormation = logicMgr.FormationManager.GetFormation(self.formationType);
    local isFormationTips = logicMgr.FormationManager.checkDefFormationRedDotByType(formationType)
    if self.formationType == EnumConst.FightTypeConst.RankBattle then
        if not logicMgr.RankBattleManager.BanPick() then
            if defaultFormation then
                local maxNum = G.dataTable["t_global"]["211"].f_int_value
                for k, v in pairs(defaultFormation) do
                    if logicMgr.RankBattleManager.IsBan(v) then
                        defaultFormation[k] = "0"
                    end
                    local num = logicMgr.RankBattleManager.HeroUsed(v)
                    if logicMgr.HeroManager.NotHaveByModeId(v) then
                        if num == maxNum then
                            defaultFormation[k] = "0"
                        end
                    end
                end
            end
        else
            if param then
                defaultFormation = logicMgr.RankBattleManager.GetBPFormation()
            end
        end
        for k, v in pairs(defaultFormation) do
            if v and v ~= 0 then
                local heroData = logicMgr.HeroManager.getHeroDatabyModelId(v, true);
                if heroData ~= nil then
                    defaultFormation[k] = tostring(heroData.partnerId)
                end
            end
        end
    end

    -- if self.formationType == EnumConst.FormationType.StoryDuplicate then --设置剧情模式默认阵容
    --     dump(dungeonHandler.hardData.groupFormation,"默认阵容长啥样")
    --     local formationData = {}
    --     for k,v in pairs(dungeonHandler.hardData.groupFormation) do
    --         local heroInfo = initHeroList[i]
    --             if heroInfo then
    --                 formationData[k] = tostring(v["partnerId"])
    --             else
    --                 formationData[k] = "0"
    --             end
    --     end
    --     defaultFormation =  logicMgr.FormationManager.GetFormation(self.formationType) or formationData;
    -- end

    for i = 1, self.formationsMax do
        self.formations[i] = {}
        self.helpManId[i] = "0";
        self.helpMan[i] = {}
        self.enemyHelpMan[i] = {}
        self.enemyHelpManId[i] = {}
        self.tabHeroPosDataTemp[i] = {}
        for j = 1, nodeCount do
            self.tabHeroPosDataTemp[i][j] = {}
        end
        for j = 1, nodeCount + 1 do
            self.formations[i][j] = "0"
        end
    end

    if defaultFormation ~= nil and #defaultFormation > 0 then
        if type(param) == "table" and param.formation then
            self.formations[1] = param.formation or {}
            self.helpManId[1] = self.formations[1][nodeCount + 1]
        else
            -- 给默认阵容赋值
            if type(defaultFormation[1]) == "table" then
                --阵容列表
                for i = 1, self.formationsMax do
                    if i <= #defaultFormation then
                        if type(defaultFormation[i]) ~= "table" then
                            defaultFormation[i] = {}
                            for sub_index = 1, nodeCount + 1 do
                                defaultFormation[i][sub_index] = "0"
                            end
                        end
                        self.formations[i] = defaultFormation[i]
                        self.helpManId[i] = self.formations[i][nodeCount + 1]
                    end
                end
            else
                -- 只是单个阵容
                self.formations[1] = defaultFormation
                self.helpManId[1] = self.formations[1][nodeCount + 1]
            end
        end
    else
        if param and param.formation then
            if self.formationsMax == 1 then
                self.formations[1] = param.formation or {}
                self.helpManId[1] = param.formation and param.formation[nodeCount + 1] or "0"
            else
                for i = 1, self.formationsMax do
                    self.formations[i] = param.formation[i] or {}
                    self.helpManId[i] = self.formations[i][nodeCount + 1]
                end
            end
        end
    end
    for i = 1, #self.formations do
        for k, v in pairs(self.formations[i]) do
            if v ~= nil and (v ~= 0 or v ~= "0") then
                local state = EnumConst.HeroHeadStateEnum.BATTLE;
                local isFind = false;
                local localModelId = 0;
                for u = 1, #self.tableHeros do
                    if tostring(self.tableHeros[u].partnerId) == tostring(v) then
                        local data = logicMgr.HeroManager.setHeroState(self.tableHeros[u].partnerId, true, state, self.formationType, self.tableHeros[u])
                        self.tableHeros[u]["state"] = data["state"]
                        localModelId = self.tableHeros[u].partnerModelId;
                        if self.tabLeaseAndOwnerHeroIndex[localModelId] ~= nil then
                            local leaseIndex = self.tabLeaseAndOwnerHeroIndex[localModelId].leaseIndex;
                            data = logicMgr.HeroManager.setHeroState(self.tableLeaseHeros[leaseIndex].partnerId, true, EnumConst.HeroHeadStateEnum.USED, self.formationType, self.tableLeaseHeros[leaseIndex])
                            self.tableLeaseHeros[leaseIndex]["state"] = data["state"]
                        end
                        break
                    end
                end
                if not isFind then
                    for j = 1, #self.tableLeaseHeros do
                        if tostring(self.tableLeaseHeros[j].partnerId) == tostring(v) then
                            local data = logicMgr.HeroManager.setHeroState(self.tableLeaseHeros[j].partnerId, true, state, self.formationType, self.tableLeaseHeros[j])
                            self.tableLeaseHeros[j]["state"] = data["state"];
                            localModelId = self.tableLeaseHeros[u].partnerModelId;
                            if self.tabLeaseAndOwnerHeroIndex[localModelId] ~= nil then
                                local leaseIndex = self.tabLeaseAndOwnerHeroIndex[localModelId].ownerIndex;
                                data = logicMgr.HeroManager.setHeroState(self.tableHeros[leaseIndex].partnerId, true, EnumConst.HeroHeadStateEnum.USED, self.formationType, self.tableHeros[leaseIndex])
                                self.tableHeros[leaseIndex]["state"] = data["state"]
                            end
                            break
                        end
                    end
                end
            end
        end
    end
    local state = EnumConst.HeroHeadStateEnum.BATTLE
    for u = 1, #self.tableHeros do
        if tostring(self.tableHeros[u].partnerId) == tostring(self.helpManId[self.formationsIndex]) then
            local data = logicMgr.HeroManager.setHeroState(self.tableHeros[u].partnerId, true, state, self.formationType, self.tableHeros[u])
            self.tableHeros[u]["state"] = data["state"]
            local localModelId = self.tableHeros[u].partnerModelId;
            if self.tabLeaseAndOwnerHeroIndex[localModelId] ~= nil then
                local leaseIndex = self.tabLeaseAndOwnerHeroIndex[localModelId].leaseIndex;
                data = logicMgr.HeroManager.setHeroState(self.tableLeaseHeros[leaseIndex].partnerId, true, EnumConst.HeroHeadStateEnum.USED, self.formationType, self.tableLeaseHeros[leaseIndex])
                self.tableLeaseHeros[leaseIndex]["state"] = data["state"]
            end
            break
        end
    end
    for j = 1, #self.tableLeaseHeros do
        if tostring(self.tableLeaseHeros[j].partnerId) == tostring(self.helpManId[self.formationsIndex]) then
            local data = logicMgr.HeroManager.setHeroState(self.tableLeaseHeros[j].partnerId, true, state, self.formationType, self.tableLeaseHeros[j])
            self.tableLeaseHeros[j]["state"] = data["state"];
            local localModelId = self.tableLeaseHeros[j].partnerModelId;
            if self.tabLeaseAndOwnerHeroIndex[localModelId] ~= nil then
                local leaseIndex = self.tabLeaseAndOwnerHeroIndex[localModelId].ownerIndex;
                data = logicMgr.HeroManager.setHeroState(self.tableHeros[leaseIndex].partnerId, true, EnumConst.HeroHeadStateEnum.USED, self.formationType, self.tableHeros[leaseIndex])
                self.tableHeros[leaseIndex]["state"] = data["state"];
            end
            break ;
        end
    end
    if fightType == EnumConst.FightTypeConst.Expedition then
        logicMgr.ExpeditionMgr.SetHeroDeadFlag()
    elseif fightType == EnumConst.FightTypeConst.LongJourneyHell then
        logicMgr.LongJourneyHellManager.SetHeroDeadFlag()
    end
end

function UIBattleTeam:setOppoFormationByType(_fightType, _param)
    -- 获取敌方阵容
    if _param ~= nil and type(_param) == "table" and _param.supSkillId then
        self.otherSupSkill = _param.supSkillId
    end
    currentFightType = _fightType
    self.oppoFormations = {}
    -- utimer.delayCall(function()
    --     AudioManager.Play(102)
    -- end, 100)

    FightManager.SetBGMSwitchByBattleType(_fightType)
    -- AudioManager.Play(114)
    if _fightType == EnumConst.FightTypeConst.DUNGEON then
        --播放 Play_mus_battle
        -- AudioManager.SetSwitch("battle_steps", "arr")
        -- AudioManager.Play(114)

        --进入布阵界面
        TAManager.TrackByDictionary("ui_battle_team_join")
        local correctLv = logicMgr.FormationManager.GetCorrectLv(_fightType);
        local monsters = logicMgr.MapManager.getMonster();
        self.powerEnemyNum = {};
        for i = 1, #monsters do
            local OppoFormation = {};
            local types = decodeJsonStrToTabel(monsters[i].occupation);
            local typesnum = 1
            for k, v in pairs(monsters[i]["team"]) do
                if k <= 5 then
                    OppoFormation[k] = {}
                    OppoFormation[k]["partnerId"] = v[1]
                    OppoFormation[k]["partnerModelId"] = v[1]
                    OppoFormation[k]["level"] =  v[2] - correctLv < 1 and  1 or  v[2] - correctLv;
                    OppoFormation[k]["star"] = v[4]
                    OppoFormation[k]["weaponLevel"] = 0
                    OppoFormation[k]["icon"] = ""
                    OppoFormation[k]["type"] = types[typesnum]
                    OppoFormation[k]["state"] = 0
                    typesnum = typesnum + 1
                elseif k == 6 then
                    self.enemyHelpMan[i] = {};
                    self.enemyHelpManId[i] = v[1]
                    self.enemyHelpMan[i]["partnerId"] = v[1]
                    self.enemyHelpMan[i]["partnerModelId"] = v[1]
                    self.enemyHelpMan[i]["level"] = v[2] - correctLv < 1 and  1 or  v[2] - correctLv;
                    self.enemyHelpMan[i]["star"] = v[4]
                    self.enemyHelpMan[i]["weaponLevel"] = 0
                    self.enemyHelpMan[i]["icon"] = ""
                    self.enemyHelpMan[i]["type"] = types[typesnum]
                    self.enemyHelpMan[i]["state"] = 0
                end
            end
            table.insert(self.oppoFormations, OppoFormation)
            table.insert(self.powerEnemyNum, monsters[i].power)
        end

    elseif _fightType == EnumConst.FightTypeConst.INSTANCE then
        local mythicFormatios = logicMgr.MythicDungeonsProManager.getFormationInfos()
        for i = 1, #mythicFormatios do
            local OppoFormation = {};
            for k, v in pairs(mythicFormatios[i]["members"]) do
                if k <= 5 then
                    OppoFormation[k] = {}
                    OppoFormation[k]["partnerId"] = v["info"][1]
                    OppoFormation[k]["partnerModelId"] = v["info"][1]
                    OppoFormation[k]["level"] = v["info"][2]
                    OppoFormation[k]["star"] = v["info"][4]
                    OppoFormation[k]["weaponLevel"] = 0
                    OppoFormation[k]["icon"] = ""
                    OppoFormation[k]["state"] = 0
                elseif k == 6 then
                    self.enemyHelpMan[i] = {}
                    self.enemyHelpManId[i] = v["info"][1]
                    self.enemyHelpMan[i]["partnerId"] = v["info"][1]
                    self.enemyHelpMan[i]["partnerModelId"] = v["info"][1]
                    self.enemyHelpMan[i]["level"] = v["info"][2]
                    self.enemyHelpMan[i]["star"] = v["info"][4]
                    self.enemyHelpMan[i]["weaponLevel"] = 0
                    self.enemyHelpMan[i]["icon"] = ""
                    self.enemyHelpMan[i]["state"] = 0
                end
            end
            table.insert(self.oppoFormations, OppoFormation)
        end
        local key = G.dataTable["t_mythicdungeons"][tostring(_param)]["f_MythicDungeonsMonsterTeamId"]
        self.powerEnemyNum = G.dataTable["t_mythicdungeonsmonsterteam"][tostring(key)]["f_DispPower"]

    elseif _fightType == EnumConst.FightTypeConst.TOWER then
        local curTowerType = logicMgr.TowerManager.getClimbType()
        --职业爬塔
        if G.dataTable["t_towertype"][tostring(curTowerType)].f_Group == EnumConst.TowerType.Advanced then
            self:AdvancedTowerDisableBtn()
        end
        local teamInfo = logicMgr.TowerManager.getTowerMonsterTeam(curTowerType)
        if teamInfo ~= nil then
            local OppoFormation = {};
            for k, v in pairs(teamInfo.team) do
                if k <= 5 then
                    OppoFormation[k] = {}
                    OppoFormation[k]["partnerId"] = v[1]
                    OppoFormation[k]["partnerModelId"] = v[1]
                    OppoFormation[k]["level"] = v[2]
                    OppoFormation[k]["star"] = v[4]
                    OppoFormation[k]["weaponLevel"] = 0
                    OppoFormation[k]["icon"] = ""
                    OppoFormation[k]["state"] = 0
                elseif k == 6 then
                    self.enemyHelpMan[1] = {}
                    self.enemyHelpManId[1] = v[1]
                    self.enemyHelpMan[1]["partnerId"] = v[1]
                    self.enemyHelpMan[1]["partnerModelId"] = v[1]
                    self.enemyHelpMan[1]["level"] = v[2]
                    self.enemyHelpMan[1]["star"] = v[4]
                    self.enemyHelpMan[1]["weaponLevel"] = 0
                    self.enemyHelpMan[1]["icon"] = ""
                    self.enemyHelpMan[1]["state"] = 0
                end
            end
            table.insert(self.oppoFormations, OppoFormation)
        end
        self.powerEnemyNum = teamInfo.power
    elseif _fightType == EnumConst.FightTypeConst.ARENA then
        local teamInfo = nil
        local teamCrossPower = nil
        if param and param.arena_type == EnumConst.ArenaBattleType.Normal then
            teamInfo = logicMgr.ArenaManager.getOppoMonster(_param.playerId)
        elseif param and param.arena_type == EnumConst.ArenaBattleType.Cross then
            teamInfo = logicMgr.ArenaManager.getCrossOppoMonster(_param.playerId)
        elseif param and param.arena_type == EnumConst.ArenaBattleType.TeamCross then
            local temp_team_info, crossPower = logicMgr.ArenaManager.getCrossTeamOppoMonster(_param.playerId)
            if temp_team_info ~= nil then
                for i = 1, #temp_team_info do
                    local OppoFormation = {}
                    for k, v in pairs(temp_team_info[i]) do
                        if k <= 5 then
                            OppoFormation[k] = {}
                            OppoFormation[k]["partnerId"] = v.partnerId
                            OppoFormation[k]["partnerModelId"] = v.partnerModelId
                            OppoFormation[k]["level"] = v.level
                            OppoFormation[k]["star"] = v.star
                            OppoFormation[k]["weaponLevel"] = v.weaponLevel or 0
                            OppoFormation[k]["weaponRank"] = v.weaponRank or 1
                            OppoFormation[k]["icon"] = ""
                            OppoFormation[k]["state"] = 0
                        elseif k == 6 then
                            self.enemyHelpMan[i] = {}
                            self.enemyHelpManId[i] = v.partnerId
                            self.enemyHelpMan[i]["partnerId"] = v.partnerId
                            self.enemyHelpMan[i]["partnerModelId"] = v.partnerModelId
                            self.enemyHelpMan[i]["level"] = v.level
                            self.enemyHelpMan[i]["star"] = v.star
                            self.enemyHelpMan[i]["weaponLevel"] = v.weaponLevel or 0
                            self.enemyHelpMan[i]["weaponRank"] = v.weaponRank or 1
                            self.enemyHelpMan[i]["icon"] = ""
                            self.enemyHelpMan[i]["state"] = 0
                        end
                    end
                    table.insert(self.oppoFormations, OppoFormation)
                end
            end
            if crossPower ~= nil then
                teamCrossPower = crossPower;
            end
        else
            error("错误竞技场类型" .. tostring(param and param.arena_type))
        end
        if teamInfo ~= nil then
            local OppoFormation = {}
            for i = 1, #teamInfo do
                if i <= nodeCount then
                    local index = teamInfo[i]["index"]
                    OppoFormation[index] = teamInfo[i]
                elseif i == nodeCount + 1 then
                    self.enemyHelpManId[self.formationsIndex] = teamInfo[i]["partnerId"]
                    self.enemyHelpMan[self.formationsIndex] = teamInfo[i]
                end
            end
            table.insert(self.oppoFormations, OppoFormation)
        end
        if teamCrossPower ~= nil then
            self.powerEnemyNum = teamCrossPower;
        else
            self.powerEnemyNum = _param.power == nil and 0 or _param.power
        end
    elseif _fightType == EnumConst.FightTypeConst.ARENARECORD then
        local teamInfo = nil
        if type(param) == "table" and param.arena_type == EnumConst.ArenaBattleType.Normal then
            teamInfo = logicMgr.ArenaManager.geRecordMonster(_param.id)
        elseif type(param) == "table" and param.arena_type == EnumConst.ArenaBattleType.Cross then
            teamInfo = logicMgr.ArenaManager.getCrossRecordMonster(_param.id)
        elseif type(param) == "table" and param.arena_type == EnumConst.ArenaBattleType.TeamCross then
            local temp_teamInfo = logicMgr.ArenaManager.getCrossTeamRecordMonster(_param.id)
            if temp_teamInfo ~= nil then
                for k = 1, #temp_teamInfo do
                    local OppoFormation = {}
                    local temp_info = temp_teamInfo[k]
                    for i = 1, #temp_info.formation do
                        for j = 1, #temp_info.members do
                            if temp_info.members[j].partnerId == temp_info.formation[i] then
                                if i <= 5 then
                                    OppoFormation[i] = temp_info.members[j]
                                elseif i == 6 then
                                    self.enemyHelpManId[k] = temp_info.members[j]["partnerId"]
                                    self.enemyHelpMan[k] = temp_info.members[j]
                                end
                            end
                        end
                    end
                    table.insert(self.oppoFormations, OppoFormation)
                end
            end
        else
            error("错误竞技场类型")
        end
        if teamInfo ~= nil then
            local OppoFormation = {}
            for i = 1, #teamInfo.formation do
                for j = 1, #teamInfo.members do
                    if teamInfo.members[j].partnerId == teamInfo.formation[i] then
                        if i <= 5 then
                            OppoFormation[i] = teamInfo.members[j]
                        elseif i == 6 then
                            self.enemyHelpManId[self.formationsIndex] = teamInfo.members[j]["partnerId"]
                            self.enemyHelpMan[self.formationsIndex] = teamInfo.members[j]
                        end
                    end
                end
            end
            table.insert(self.oppoFormations, OppoFormation)
        end
        self.powerEnemyNum = _param.power == nil and 0 or _param.power

    elseif _fightType == EnumConst.FightTypeConst.Expedition then
        local info = logicMgr.ExpeditionMgr.GetStageInfo(_param);
        if info ~= nil then
            local OppoFormation = {};
            local formation = info.formation
            for k, v in pairs(formation) do
                if k <= 5 and v.hp > 0 then
                    local star = dataTable.getDataTableByStringId("t_hero", v.modelId, "f_HeroInitialStar")
                    table.insert(OppoFormation, { partnerModelId = v.modelId, partnerId = k, level = v.level, star = star, weaponLevel = 0 })
                elseif k == 6 and v.hp > 0 then
                    local star = dataTable.getDataTableByStringId("t_hero", v.modelId, "f_HeroInitialStar")
                    self.enemyHelpManId[self.formationsIndex] = k
                    self.enemyHelpMan[self.formationsIndex] = { partnerModelId = v.modelId, partnerId = k, level = v.level, star = star, weaponLevel = 0 };
                end
            end
            table.insert(self.oppoFormations, OppoFormation)
            self.powerEnemyNum = info.power
        end
    elseif _fightType == EnumConst.FightTypeConst.TRIAL then
        local OppoFormation = {}
        for i = 1, 5 do
            local item = _param[i] or {}
            if item["partnerId"] == "0" then
                item["partnerId"] = nil
            end
            table.insert(OppoFormation, item)
        end
        table.insert(self.oppoFormations, OppoFormation)
        self.powerEnemyNum = logicMgr.TrialsManager.getBossPower()
    elseif _fightType == EnumConst.FightTypeConst.SoloChaosTest then
        self.powerEnemyNum = {};
        if param and param.oppo_formation then
            for j = 1, self.formationsMax do
                local powerSum = 0
                local teamInfo = param.oppo_formation[j]
                if teamInfo ~= nil then
                    local OppoFormation = {}
                    for i = 1, #teamInfo do
                        if i <= 5 then
                            OppoFormation[i] = teamInfo[i]
                        elseif i == 6 then
                            if teamInfo[i] and next(teamInfo[i]) ~= nil then
                                self.enemyHelpManId[j] = teamInfo[i]["partnerId"]
                                self.enemyHelpMan[j] = teamInfo[i]
                            else
                                self.enemyHelpManId[j] = nil
                            end
                        end
                    end
                    table.insert(self.oppoFormations, OppoFormation);
                    self.powerEnemyNum[j] = param.power or 0
                else
                    table.insert(self.oppoFormations, {});
                    self.enemyHelpManId[j] = nil
                    self.powerEnemyNum[j] = 0
                end
            end
        end
    elseif _fightType == EnumConst.FightTypeConst.FriendAttack then
        local teamInfo, skillId = logicMgr.FriendBattleManager.GetFormationById(_param)
        self.otherSupSkill = skillId;
        self.powerEnemyNum = 0
        if teamInfo ~= nil then
            local OppoFormation = {};
            for k, v in pairs(teamInfo) do
                local config = v.partner
                if k <= 5 then
                    OppoFormation[k] = {};
                    OppoFormation[k]["partnerId"] = config.partnerId
                    OppoFormation[k]["partnerModelId"] = config.partnerModelId
                    OppoFormation[k]["level"] = config.level
                    OppoFormation[k]["star"] = config.star
                    OppoFormation[k]["weaponLevel"] = config.weaponLevel
                    OppoFormation[k]["icon"] = "";
                    OppoFormation[k]["state"] = nil;
                    OppoFormation[k]["state"] = 0;
                    self.powerEnemyNum = self.powerEnemyNum + config.fightVal
                elseif k == 6 then
                    self.enemyHelpMan[1] = {};
                    self.enemyHelpManId[1] = config
                    self.enemyHelpMan[1]["partnerId"] = config.partnerId
                    self.enemyHelpMan[1]["partnerModelId"] = config.partnerModelId
                    self.enemyHelpMan[1]["level"] = config.level
                    self.enemyHelpMan[1]["star"] = config.star
                    self.enemyHelpMan[1]["weaponLevel"] = config.weaponLevel
                    self.enemyHelpMan[1]["icon"] = "";
                    self.enemyHelpMan[1]["state"] = nil;
                    self.enemyHelpMan[1]["state"] = 0;
                    self.powerEnemyNum = self.powerEnemyNum + config.fightVal
                end
            end
            table.insert(self.oppoFormations, OppoFormation)
        end
    elseif _fightType == EnumConst.FightTypeConst.RankBattle then
        if logicMgr.RankBattleManager.BanPick() then
            local _, enemyformation = logicMgr.RankBattleManager.GetBPFormation()
            local OppoFormation = {};
            for k, v in pairs(enemyformation) do
                local config = logicMgr.RankBattleManager.SeasonBanHero(v)
                if config then
                    if k <= 5 then
                        OppoFormation[k] = {}
                        OppoFormation[k]["partnerId"] = config.partnerId
                        OppoFormation[k]["partnerModelId"] = config.partnerModelId
                        OppoFormation[k]["level"] = 300
                        OppoFormation[k]["star"] = 150
                        OppoFormation[k]["weaponLevel"] = 0
                        OppoFormation[k]["icon"] = ""
                        OppoFormation[k]["state"] = 0
                    elseif k == 6 then
                        self.enemyHelpMan[1] = {}
                        self.enemyHelpManId[1] = config
                        self.enemyHelpMan[1]["partnerId"] = config.partnerId
                        self.enemyHelpMan[1]["partnerModelId"] = config.partnerModelId
                        self.enemyHelpMan[1]["level"] = 300
                        self.enemyHelpMan[1]["star"] = 150
                        self.enemyHelpMan[1]["weaponLevel"] = 0
                        self.enemyHelpMan[1]["icon"] = ""
                        self.enemyHelpMan[1]["state"] = 0
                    end
                end
            end
            table.insert(self.oppoFormations, OppoFormation)
        end
    elseif _fightType == EnumConst.FightTypeConst.FriendCompeteBattle or _fightType == EnumConst.FightTypeConst.GuildFriendCompeteBattle then
        FightManager.SetBGMSwitchByBattleType(EnumConst.FightTypeConst.TRIAL)
        AudioManager.SetSwitch("Battle_SwitchGroup", "arena")
        local info = logicMgr.FriendManager.GetFriendCompeteBattleInfo()
        if _param.isFriend then
            self.competeBattleWinsCtrl:SetSelectedIndex(1)
            self.otherWinTimerText.text = param.competeTimes - param.wins
            self.myWinTimerText.text = param.wins
        else
            self.competeBattleWinsCtrl:SetSelectedIndex(0)
        end

        local teamInfo = info.formation
        local powerSum = 0
        if teamInfo ~= nil then
            local OppoFormation = {}
            for i = 1, #teamInfo do
                teamInfo[i].weaponLevel = teamInfo[i].weaponLv;
                if i <= 5 then
                    if tonumber(tostring(teamInfo[i]["partnerId"])) ~= 0 then
                        OppoFormation[i] = teamInfo[i];
                        powerSum = powerSum + teamInfo[i].fightVal
                    else
                        OppoFormation[i] = teamInfo[i];
                        OppoFormation[i]["partnerId"] = nil;
                    end
                elseif i == 6 then
                    if tonumber(tostring(teamInfo[i]["partnerId"])) ~= 0 then
                        self.enemyHelpManId[self.formationsIndex] = teamInfo[i]["partnerId"];
                        self.enemyHelpMan[self.formationsIndex] = teamInfo[i];
                        powerSum = powerSum + teamInfo[i].fightVal;
                    else
                        self.enemyHelpManId[self.formationsIndex] = nil;
                    end
                end
            end
            table.insert(self.oppoFormations, OppoFormation)
        end
        self.powerEnemyNum = powerSum
    elseif _fightType == EnumConst.FightTypeConst.Plunder then
        if param and param.oppo_formation then
            local powerSum = 0
            local teamInfo = param.oppo_formation
            if teamInfo ~= nil then
                local OppoFormation = {}
                for i = 1, #teamInfo do
                    if i <= 5 then
                        if teamInfo[i] and tonumber(tostring(teamInfo[i]["partnerId"])) ~= 0 then
                            OppoFormation[i] = teamInfo[i]
                            if teamInfo[i].power ~= nil then
                                powerSum = powerSum + teamInfo[i].power
                            end
                        else
                            OppoFormation[i] = teamInfo[i]
                            OppoFormation[i]["partnerId"] = nil
                        end
                    elseif i == 6 then
                        if teamInfo[i] and tonumber(tostring(teamInfo[i]["partnerId"])) ~= 0 then
                            self.enemyHelpManId[self.formationsIndex] = teamInfo[i]["partnerId"]
                            self.enemyHelpMan[self.formationsIndex] = teamInfo[i]
                            if teamInfo[i].power ~= nil then
                                powerSum = powerSum + teamInfo[i].power
                            end
                        else
                            self.enemyHelpManId[self.formationsIndex] = nil
                        end
                    end
                end
                table.insert(self.oppoFormations, OppoFormation);
            end
            self.powerEnemyNum = powerSum
        end
    elseif _fightType == EnumConst.FightTypeConst.GuildBattlePlus then
        self.powerEnemyNum = {};
        if param and param.oppo_formation then
            for j = 1, self.formationsMax do
                local powerSum = 0
                local teamInfo = param.oppo_formation[j]
                if teamInfo ~= nil then
                    local OppoFormation = {}
                    for i = 1, #teamInfo do
                        if i <= 5 then
                            if teamInfo[i] and next(teamInfo[i]) ~= nil then
                                OppoFormation[i] = teamInfo[i]
                                if teamInfo[i].power ~= nil then
                                    powerSum = powerSum + tonumber(tostring(teamInfo[i].power))
                                end
                            else
                                OppoFormation[i] = teamInfo[i]
                                OppoFormation[i]["partnerId"] = nil
                            end
                        elseif i == 6 then
                            if teamInfo[i] and next(teamInfo[i]) ~= nil then
                                self.enemyHelpManId[j] = teamInfo[i]["partnerId"]
                                self.enemyHelpMan[j] = teamInfo[i]
                                if teamInfo[i].power ~= nil then
                                    powerSum = powerSum + tonumber(tostring(teamInfo[i].power))
                                end
                            else
                                self.enemyHelpManId[j] = nil
                            end
                        end
                    end
                    table.insert(self.oppoFormations, OppoFormation);
                    self.powerEnemyNum[j] = powerSum
                else
                    table.insert(self.oppoFormations, {});
                    self.enemyHelpManId[j] = nil
                    self.powerEnemyNum[j] = 0
                end
            end

        end
    elseif _fightType == EnumConst.FightTypeConst.LongJourneyHell then
        self.powerEnemyNum = {};
        if param and param.oppo_formation then
            for j = 1, self.formationsMax do
                local teamInfo = param.oppo_formation[j]
                if teamInfo ~= nil then
                    local OppoFormation = {}
                    for i = 1, #teamInfo do
                        if i <= 5 then
                            OppoFormation[i] = teamInfo[i]
                        elseif i == 6 then
                            if teamInfo[i] and next(teamInfo[i]) ~= nil then
                                self.enemyHelpManId[j] = teamInfo[i]["partnerId"]
                                self.enemyHelpMan[j] = teamInfo[i]
                            else
                                self.enemyHelpManId[j] = nil
                            end
                        end
                    end
                    table.insert(self.oppoFormations, OppoFormation);
                    self.powerEnemyNum[j] = param.power or 0
                else
                    table.insert(self.oppoFormations, {});
                    self.enemyHelpManId[j] = nil
                    self.powerEnemyNum[j] = 0
                end
            end
        end
    elseif _fightType == EnumConst.FightTypeConst.DungeonEventPK then
        local teamInfo = param.enemyFormation;
        local powerSum = 0
        if teamInfo ~= nil then
            local OppoFormation = {}
            for i = 1, #teamInfo do
                teamInfo[i].weaponLevel = teamInfo[i].weaponLv;
                if i <= 5 then
                    if tonumber(tostring(teamInfo[i]["partnerId"])) ~= 0 then
                        OppoFormation[i] = teamInfo[i];
                        powerSum = powerSum + teamInfo[i].fightVal
                    else
                        OppoFormation[i] = teamInfo[i];
                        OppoFormation[i]["partnerId"] = nil;
                    end
                elseif i == 6 then
                    if tonumber(tostring(teamInfo[i]["partnerId"])) ~= 0 then
                        self.enemyHelpManId[self.formationsIndex] = teamInfo[i]["partnerId"];
                        self.enemyHelpMan[self.formationsIndex] = teamInfo[i];
                        powerSum = powerSum + teamInfo[i].fightVal;
                    else
                        self.enemyHelpManId[self.formationsIndex] = nil;
                    end
                end
            end
            table.insert(self.oppoFormations, OppoFormation);
        end
        self.powerEnemyNum = powerSum;
    elseif _fightType == EnumConst.FightTypeConst.StoryBattle then
        --设置enemy阵容
        -- self:setOppoFormationByType(_fightType)
        local id = 0
        if dungeonHandler.hardData.maxPassDungeon == 0 then
            id = 101
        else
            id = G.dataTable["t_stagehardmode"][tostring(dungeonHandler.hardData.maxPassDungeon)].f_NextStage
            if id == -1 then
                id = G.dataTable["t_stagehardmode"][tostring(dungeonHandler.hardData.maxPassDungeon)].f_Id
            end
        end
        local monsters = logicMgr.MapManager.getHardMonster(id);
        self.powerEnemyNum = {};
        for i = 1, #monsters do
            local OppoFormation = {};
            local types = decodeJsonStrToTabel(monsters[i].occupation);
            local typesnum = 1
            for k, v in pairs(monsters[i]["team"]) do
                if k <= 5 then
                    OppoFormation[k] = {}
                    OppoFormation[k]["partnerId"] = v[1]
                    OppoFormation[k]["partnerModelId"] = v[1]
                    OppoFormation[k]["level"] = v[2]
                    OppoFormation[k]["star"] = v[4]
                    OppoFormation[k]["weaponLevel"] = 0
                    OppoFormation[k]["icon"] = ""
                    OppoFormation[k]["type"] = types[typesnum]
                    OppoFormation[k]["state"] = 0
                    typesnum = typesnum + 1
                elseif k == 6 then
                    self.enemyHelpMan[i] = {};
                    self.enemyHelpManId[i] = v[1]
                    self.enemyHelpMan[i]["partnerId"] = v[1]
                    self.enemyHelpMan[i]["partnerModelId"] = v[1]
                    self.enemyHelpMan[i]["level"] = v[2]
                    self.enemyHelpMan[i]["star"] = v[4]
                    self.enemyHelpMan[i]["weaponLevel"] = 0
                    self.enemyHelpMan[i]["icon"] = ""
                    self.enemyHelpMan[i]["type"] = types[typesnum]
                    self.enemyHelpMan[i]["state"] = 0
                end
            end
            table.insert(self.oppoFormations, OppoFormation)
            table.insert(self.powerEnemyNum, monsters[i].power)
        end
    end
    for i, v in pairs(self.oppoFormations) do
        for idx, member in pairs(v) do
            if tostring(tonumber(member["partnerId"])) == 0 then
                member["partnerId"] = nil;
                member["partnerModelId"] = nil;
                member["skinId"] = nil;
            end
            if tonumber(tostring(member["skinId"])) == 0 then
                member["skinId"] = nil;
            end
        end
    end
end
--- 并没有真正退出,而是弹出弹窗
function UIBattleTeam:onClickBack1()
    local flag = false;
    if fightType == EnumConst.FightTypeConst.DUNGEON or fightType == EnumConst.FightTypeConst.StoryBattle then
        TAManager.TrackByDictionary("ui_battle_team_click_back")
        local data = logicMgr.BattlePlaybackManager.GetGroupBossHistory();
        for k, v in pairs(data) do
            if v.record and v.record.win == 1 then
                flag = true
                break
            end
        end
    end
    if flag then
        local pop = CtrlManager.GetCtrl(PanelNames.UICommonPop);
        pop.Init("62", function(b)
            if b then
                if fightType == EnumConst.FightTypeConst.DUNGEON then
                    dungeonHandler.reqQuitGroupBoss();
                elseif fightType == EnumConst.FightTypeConst.StoryBattle then
                    dungeonHandler.ReqQuitHardGroupBoss()
                end
                self:onClickBack()
            end
        end);
    elseif self.formationType == EnumConst.FightTypeConst.RankBattle then
        local pop = CtrlManager.GetCtrl(PanelNames.UICommonPop)
        pop.Init("34", function(b)
            if b then
                logicMgr.HeroManager.AllRestRankHero()
                RankBattleHandler.ReqRankBattleQuitMatch()
                self:onClickBack()
                closeUI(PanelResNames.UIRankBattleTeam)
            end
        end);
    else
        self:onClickBack()
    end
end
--- 真正退出
function UIBattleTeam:onClickBack()
    local self = UIBattleTeam
    local is = false
    if fightType == EnumConst.FightTypeConst.ARENA or fightType == EnumConst.FightTypeConst.StoryBattle then
        is = logicMgr.ArenaManager.getSomeBattleSkip();
    end
    if self.formationType == EnumConst.FightTypeConst.FriendDefend
            or self.formationType == EnumConst.FightTypeConst.FriendAttack
    then
        is = logicMgr.ArenaManager.getSomeBattleSkip();
    end
    logicMgr.ArenaManager.setSomeBattleSkip(is);
    partnerHandler.clearInteractionSaveData()
    if self.isFriendBattle then
        closeUI(PanelNames.UITeam)
    end
    closeUI(PanelNames.UIBattleTeam)
    for i = 1, 2 do
        for k, v in pairs(self.playRestrainTimeList[i]) do
            if v then
                utimer.remove(v)
            end
        end
        self.playRestrainTimeList[i] = {}
    end
    --if self.isNeedOpenHeadMenu then
    --    showUI(PanelNames.UIHeadMenu, true)
    --end
    logicMgr.BattlePlaybackManager.SetGroupBossHistory()
    if self.backFunction ~= nil then
        self.backFunction()
    end
end
function UIBattleTeam:DelayEnableClick()
    self.isClickBattle = false
end

function UIBattleTeam:onClickBoss()
    if self.isClickBattle then
        return
    end
    self.isClickBattle = true;
    self:TimeCall(self.DelayEnableClick, 1500)
    if currentFightType == EnumConst.FightTypeConst.DUNGEON then
        TAManager.TrackByDictionary("ui_battle_team_click_fight")
    elseif currentFightType == EnumConst.FightTypeConst.ARENA then
    elseif currentFightType == EnumConst.FightTypeConst.Expedition then
        TAManager.TrackByDictionary("expedition_battle_click_fight", { expedition_stage_id = ExpeditionMgr.GetCurStageId() })
    elseif currentFightType == EnumConst.FightTypeConst.Expedition then
        -- todo
    end
    local self = UIBattleTeam
    for i = 1, self.formationsMax do
        if self.helpManId[i] ~= 0 and self.formations[i] then
            self.formations[i][nodeCount + 1] = self.helpManId[i] or "0"
        end
        for j = 1, nodeCount do
            if self.formations[i][j] == nil then
                self.formations[i][j] = "0"
            end
        end
    end
    if self.checkFunction ~= nil and not self.checkFunction(self.formations) then
        AudioManager.Play(2010)
        return
    end

    if self.formationType == EnumConst.FormationType.TeamCrossArenaDef
            or self.formationType == EnumConst.FormationType.TeamCrossArenaAtk then
        local flag = false
        local formation = self.formations[self.formationsIndex]
        for k = 1, #formation do
            if k <= nodeCount then
                if formation[k] ~= nil and tonumber(tostring(formation[k])) ~= 0 then
                    flag = true
                    break
                end
            end
        end
        if not flag then
            UISysTips.AddMsg("每个阵容至少需要上阵一名英雄")
            AudioManager.Play(2010)
            self.ctrlNumTeams:SetSelectedIndex(self.formationsIndex)
            return
        end
    end

    if self.formationType == EnumConst.FormationType.MythicDungeons and self.formationsIndex == 1 then
        self.ctrlNumTeams.selectedIndex = 2
        self.isChangTeam = true;
        self.lastHelpManId = self.helpMan[self.formationsIndex].partnerModelId;
        self:onClickItemIndex(2)
        self.isChangTeam = false;
        AudioManager.Play(1033)
        self.isClickBattle = false;
        return
    elseif self.formationType == EnumConst.FormationType.TeamCrossArenaDef
            or self.formationType == EnumConst.FormationType.TeamCrossArenaAtk
    then
        if self.formationsIndex == 1 then
            self.ctrlNumTeams:SetSelectedIndex(2)
            self.isChangTeam = true;
            self.lastHelpManId = self.helpMan[self.formationsIndex].partnerModelId;
            self:onClickItemIndex(2)
            self.isChangTeam = false;
            AudioManager.Play(1033)
            self.isClickBattle = false
            return
        elseif self.formationsIndex == 2 then
            self.ctrlNumTeams:SetSelectedIndex(3)
            self.isChangTeam = true;
            self.lastHelpManId = self.helpMan[self.formationsIndex].partnerModelId;
            self:onClickItemIndex(3)
            self.isChangTeam = false;
            AudioManager.Play(1033)
            self.isClickBattle = false
            return
        end
    elseif self.formationType == EnumConst.FormationType.GuildBattlePlus then
        for i = self.formationsIndex + 1, self.formationsMax do
            if not (param.formationIsOver and param.formationIsOver[i]) then
                local nextIndex = i;
                self.ctrlNumTeams:SetSelectedIndex(nextIndex)
                self:onClickItemIndex(nextIndex)
                AudioManager.Play(1033)
                self.isClickBattle = false
                return
            end
        end
    elseif self.formationType == EnumConst.FormationType.StoryDuplicate or self.formationType == EnumConst.FormationType.DuplicateMore then
    else
        if self.formationsIndex < self.formationsMax then
            local nextIndex = self.formationsIndex + 1;
            self.ctrlNumTeams:SetSelectedIndex(nextIndex)
            self:onClickItemIndex(nextIndex)
            AudioManager.Play(1033)
            self.isClickBattle = false
            return
        end
    end
    if self.battleBossFunction ~= nil then
        if self.formations then
            local fflag = true
            for i = 1, #self.formations do
                -- 多队推图只检测当前队
                if self.formationType == EnumConst.FormationType.StoryDuplicate or self.formationType == EnumConst.FormationType.DuplicateMore then
                    i = self.formationsIndex
                    -- elseif (self.formationType == EnumConst.FormationType.TeamCrossArenaAtk
                    --     or self.formationType == EnumConst.FormationType.TeamCrossArenaDef )
                    --     and fightType == EnumConst.FightTypeConst.ARENA
                    -- then
                    --     i = self.formationsIndex
                end
                local flag = false;
                for k = 1, #self.formations[i] do
                    if k <= nodeCount then
                        if self.formations[i][k] ~= nil and tonumber(tostring(self.formations[i][k])) ~= 0 then
                            flag = true
                            break
                        end
                    end
                end
                if fightType == EnumConst.FightTypeConst.GuildBattlePlus then
                    if param.formationIsOver and param.formationIsOver[i] then
                        flag = true
                    end
                end
                if not flag then
                    fflag = false
                    UISysTips.AddMsg("每个阵容至少需要上阵一名英雄")
                    AudioManager.Play(2010)
                    self.isClickBattle = false
                    break
                end
                if fightType == EnumConst.FightTypeConst.DUNGEON then
                    break
                    -- elseif ( self.formationType == EnumConst.FormationType.TeamCrossArenaAtk
                    --     or self.formationType == EnumConst.FormationType.TeamCrossArenaDef )
                    --     and fightType == EnumConst.FightTypeConst.ARENA
                    -- then
                    --     break
                end
            end
            if fflag then
                --if (self.formationType == EnumConst.FormationType.ArenaDef and fightType == EnumConst.FightTypeConst.ARENA)
                --        or self.formationType == EnumConst.FormationType.CrossArenaDef
                --        --or self.formationType == EnumConst.FormationType.FriendDefend
                --        or self.formationType == EnumConst.FormationType.PlunderBattle then
                if self.btnController.selectedIndex == 1 then
                    local flag = false;
                    for i = 1, #self.formations do
                        for k, v in pairs(self.formations[i]) do
                            local level = logicMgr.HeroManager.getHeroShowLevelByPartnerId(tostring(v));
                            if tonumber(level) == 1 then
                                if self.formationType ~= EnumConst.FormationType.FriendDefend and self.formationType ~= EnumConst.FormationType.CrossArenaDef
                                        and self.formationType ~= EnumConst.FormationType.TeamCrossArenaDef then
                                    UISysTips.AddMsg(getLanguage("DefendRedTips"));
                                end
                                flag = true
                                break
                            end
                        end
                        if flag then
                            break
                        end
                    end
                end
                for i = 1, 2 do
                    for k, v in pairs(self.playRestrainTimeList[i]) do
                        if v then
                            utimer.remove(v)
                        end
                    end
                    self.playRestrainTimeList[i] = {}
                end
                AudioManager.Play(1033)
                self.battleInfo.myHelpManId = self.helpManId
                self.battleInfo.enemyHelpManId = self.enemyHelpManId

                local tempForms = {};
                for i = 1, #self.oppoFormations do
                    local form = clone(self.oppoFormations[i]);
                    table.insert(form, self.enemyHelpMan[i])
                    table.insert(tempForms, form)
                end
                BattleSceneCacheResouce:CacheBattleFormation(self.formations, tempForms)
                FightManager.SetMyTeam(self.tabHeroPosData, self.helpMan[self.formationsIndex].partnerModelId)
                FightManager.isAuto = nil
                FightManager.battleFunction = nil
                if self.isFriendBattle then
                    self.battleBossFunction(UIBattleTeam:SetFriendBattleFormation())
                    if logicMgr.ArenaManager.getSomeBattleSkip() then

                    else
                        closeUI(PanelNames.UIBattleTeam)
                        closeUI(PanelResNames.UITeam)
                    end
                    --FriendBattleHandler.ReqFriendBattleInfo()
                else
                    if currentFightType == EnumConst.FightTypeConst.DUNGEON then
                        local mapCfg = MapManager.getMapcfg();
                        if not string.IsNilOrEmpty(mapCfg.f_ReportAddress) then
                            --前四关直接播放战报
                            local id = mapCfg.f_ReportAddress
                            BattlePlaybackManager.playReport(id)
                        end
                    end
                    FightManager.paramTeamBonus = {}
                    FightManager.paramTeamBonus.tabHeroPosData = clone(self.tabHeroPosData);
                    FightManager.paramTeamBonus.helpMan = clone(self.helpMan);
                    --if fightType == EnumConst.FightTypeConst.DUNGEON then
                    --    if self.formationsMax > 1 then
                    --        -- 多队
                    --        logicMgr.FormationManager.TempDungeonFormationMore(self.formations);
                    --    else
                    --        -- 单队
                    --        logicMgr.FormationManager.TempDungeonFormation(self.formations[1]);
                    --    end
                    --    local battleFormation = {};
                    --    for i = 1, #self.formations do
                    --        battleFormation[i] = {};
                    --        for k = 1, #self.formations[i] do
                    --            local lcDungeonFormtaion = DungeonFormtaion.New();
                    --            if self.formations[i][k] ~= nil and tonumber(tostring(self.formations[i][k])) ~= 0 then
                    --                local localPartnerId = self.formations[i][k];
                    --                local hero = logicMgr.HeroManager.getHeroDatabyPartnerId(localPartnerId, true);
                    --                lcDungeonFormtaion.partnerId = localPartnerId;
                    --                if hero == nil then
                    --                    lcDungeonFormtaion.lend = 1;
                    --                    --battleFormation[i][k] = { partnerId = localPartnerId, lend = 1 };
                    --                    battleFormation[i][k] = lcDungeonFormtaion;
                    --                else
                    --                    --battleFormation[i][k] = { partnerId = localPartnerId, lend = 2 };
                    --                    lcDungeonFormtaion.lend = 2;
                    --                    battleFormation[i][k] = lcDungeonFormtaion;
                    --                end
                    --            else
                    --                lcDungeonFormtaion.partnerId = "0";
                    --                lcDungeonFormtaion.lend = 2;
                    --                battleFormation[i][k] = lcDungeonFormtaion;
                    --                --battleFormation[i][k] = { partnerId = "0", lend = 2 };
                    --            end
                    --        end
                    --    end
                    --    self.battleBossFunction(battleFormation, self.oppoFormations, self.battleInfo, self.formationsIndex)
                    --else
                    FightManager.isAuto = nil
                    if FuncOpenManager.isOpen(Config.FuncOpenType.autoAttack) then
                        local key = "UIBattleMainAuto" .. currentFightType .. logicMgr.HeroManager.GetRoleInfo("playerId");
                        if currentFightType == EnumConst.FightTypeConst.DUNGEON then
                            if GetPlayerPrefs("UIBattleMainAuto" .. logicMgr.HeroManager.GetRoleInfo("playerId")) then
                                if tonumber(GetPlayerPrefs("UIBattleMainAuto" .. logicMgr.HeroManager.GetRoleInfo("playerId"))) == 1 then
                                    FightManager.isAuto = true
                                end
                            end
                        elseif currentFightType == EnumConst.FightTypeConst.TOWER then
                            key = key .. "_" .. logicMgr.TowerManager.getClimbType();
                            if GetPlayerPrefs(key) then
                                if tonumber(GetPlayerPrefs(key)) == 1 then
                                    FightManager.isAuto = true
                                end
                            end
                        elseif currentFightType == EnumConst.FightTypeConst.StoryBattle then
                            if GetPlayerPrefs(key) then
                                if tonumber(GetPlayerPrefs(key)) == 1 then
                                    FightManager.isAuto = true
                                end
                            end
                            --else
                            --if GetPlayerPrefs(key) then
                            --    if tonumber(GetPlayerPrefs(key)) == 1 then
                            --        FightManager.isAuto = true
                            --    end
                            --end
                        end
                    end
                    FightManager.battleFunction = function()
                        self.battleBossFunction(self.formations, self.oppoFormations, self.battleInfo, self.formationsIndex)
                    end
                    FightManager.battleFunction()

                    --end

                    ---主线副本添加好感度
                    if currentFightType == EnumConst.FightTypeConst.DUNGEON then
                        if not table.isNullOrEmpty((self.formations or {})[1]) then
                            local datas = {}
                            for i, v in ipairs(self.formations[1]) do
                                if logicMgr.HeroFavorManager.checkCanFavorInteract(v, 2001) then
                                    local heroData = logicMgr.HeroManager.getHeroDatabyPartnerId(v, true)
                                    if not table.isNullOrEmpty(heroData) then
                                        local data = {}
                                        data.partnerId = heroData.partnerId
                                        data.lastLevel = heroData.favorLv
                                        data.lastExp = heroData.favorExp
                                        table.insert(datas, data)
                                    end
                                end
                            end
                            partnerHandler.setInteractionSaveData(datas, 2001)
                        end
                    end
                end
            end
        end
    end
end

function UIBattleTeam:onClickManual()
    -- 攻略
    if fightType == EnumConst.FightTypeConst.DUNGEON then
        local formation_type = logicMgr.BattlePlaybackManager.GetFormationType()
        showUI(PanelNames.UIChapterRecord, nil, EnumConst.FightTypeConst.DUNGEON, nil, function()
            UIBattle.onClickBoss()
        end, nil, formation_type)
    elseif fightType == EnumConst.FightTypeConst.StoryBattle then
        local formation_type = logicMgr.BattlePlaybackManager.GetFormationType()
        showUI(PanelNames.UIChapterRecord, nil, EnumConst.FightTypeConst.StoryBattle, nil, function()
            UIBattle.onClickBoss()
        end, nil, formation_type)
    end
end

function UIBattleTeam:processHeroData(heroData, data, _data)
    if data == nil then
        return {};
    end
    heroData.partnerId = data.partnerId
    heroData.partnerModelId = tonumber(data.partnerModelId)
    if self.formationType == EnumConst.FormationType.RankBattle then
        heroData.level = 300
    else
        heroData.level = data.level
    end
    heroData.star = tonumber(data.star)
    local _heroData = logicMgr.HeroManager.getHeroDatabyPartnerId(heroData.partnerId, true)
    if _heroData then
        heroData.icon = _heroData.icon
        heroData.skinId = _heroData.skinId
    else
        _heroData = logicMgr.HeroManager.getHeroDatabyModelId(heroData.partnerModelId, true)
        if _heroData then
            heroData.icon = _heroData.icon
        end
        heroData.skinId = heroData.skinId
    end
    heroData.type = data.type
    heroData.isDead = false
    if data.isOver and _data and _data.battleDetail then
        for k, v in pairs(_data.battleDetail) do
            if heroData.partnerModelId == v.partnerModelId then
                heroData.isDead = tonumber(tostring(v.hp)) <= 0;
            end
        end
    end
end
--- 技能策略
function UIBattleTeam:onClickHeroTactics()
    local data = {}
    local data2 = {}
    for j = 1, 5 do
        local heroData = {}
        local heroData2 = {}
        self:processHeroData(heroData, self.tabHeroPosDataTemp[self.formationsIndex][j])
        self:processHeroData(heroData2, self.oppoFormations[self.formationsIndex][j])
        if self.formationType == EnumConst.FormationType.TrialsChaos or self.formationType == EnumConst.FormationType.SoloChaosTest then
            heroData2.level = nil;
        end
        heroData.index = j;
        heroData2.index = j;
        table.insert(data, heroData)
        table.insert(data2, heroData2)
    end
    local heroData = {}
    local heroData2 = {}
    self:processHeroData(heroData, self.helpMan[self.formationsIndex])
    self:processHeroData(heroData2, self.enemyHelpMan[self.formationsIndex])
    heroData.index = 6;
    heroData2.index = 6;
    table.insert(data, heroData)
    table.insert(data2, heroData2)
    showUI(PanelNames.UIHeroTactics, nil, self.formationType, data, data2)
end

function UIBattleTeam:onClickQuickChange()
    -- 快速换队
    local formationsList = {}
    formationsList.myFormationsList = {}
    formationsList.enemyFormationsList = {}
    for i = 1, self.formationsMax do
        local data = {}
        local data2 = {}
        data.isOver = false
        data2.isOver = true
        -- if condition then
        --     -- 加类型判断
        -- end
        local _data = logicMgr.BattlePlaybackManager.GetGroupBossHistory(i)
        if _data and _data.record and _data.record.win == 1 then
            data.isOver = true
        end
        data.heroList = {}
        data2.heroList = {}
        for j = 1, 5 do
            local heroData = {}
            local heroData2 = {}
            self:processHeroData(heroData, self.tabHeroPosDataTemp[i][j], _data)
            if self.oppoFormations and self.oppoFormations[i] and self.oppoFormations[i][j] then
                self:processHeroData(heroData2, self.oppoFormations[i][j])
            end
            if data.isOver then
                heroData2.isDead = true
            end
            table.insert(data.heroList, heroData)
            table.insert(data2.heroList, heroData2)
        end
        local heroData = {}
        local heroData2 = {}
        self:processHeroData(heroData, self.helpMan[i], _data)
        self:processHeroData(heroData2, self.enemyHelpMan[i])
        if data.isOver then
            heroData2.isDead = true
        end
        table.insert(data.heroList, heroData)
        table.insert(data2.heroList, heroData2)
        table.insert(formationsList.myFormationsList, data)
        table.insert(formationsList.enemyFormationsList, data2)
    end
    local isMyTeamEmpty = true
    for _, v in pairs(formationsList.myFormationsList) do
        for _, n in pairs(v.heroList) do
            if n.partnerId and tonumber(n.partnerId) > 0 then
                isMyTeamEmpty = false
                break
            end
        end
    end
    if isMyTeamEmpty then
        UISysTips.AddMsg(getLanguage("TeamQuickchangeTips"))
        return
    end
    formationsList.myData = {};
    formationsList.myData.pic = logicMgr.HeroManager.GetRoleHeadID()
    formationsList.myData.picFrame = logicMgr.HeroManager.GetRoleHeadFrame()
    formationsList.myData.name = logicMgr.HeroManager.GetRoleName()
    formationsList.enemyData = {}
    formationsList.enemyData.pic = formationsList.enemyFormationsList[1].heroList[1].partnerModelId
    formationsList.enemyData.picFrame = 800001
    if fightType == EnumConst.FightTypeConst.ARENA then
        formationsList.enemyData.name = param.name;
        formationsList.enemyData.pic = param.pic
    elseif fightType == EnumConst.FightTypeConst.INSTANCE then
        formationsList.enemyData.name = string.format(getLanguage("ClimbTower_Level"), param)
    elseif fightType == EnumConst.FightTypeConst.StoryBattle then
        local mapNextCfg = logicMgr.StoryHardManager.getDungeonTableDataById();
        formationsList.enemyData.name = string.format("关卡%s-%s", mapNextCfg.f_ChapterId, mapNextCfg.f_StageNum)
    elseif fightType == EnumConst.FightTypeConst.SoloChaosTest then
        formationsList.enemyData.name = param.name
        formationsList.enemyData.pic = param.pic
    elseif fightType == EnumConst.FightTypeConst.GuildBattle
        or fightType == EnumConst.FightTypeConst.GuildBattlePlus
    then
        formationsList.enemyData.name = param.oppo_name
        formationsList.enemyData.pic = param.oppo_pic
    else
        local mapNextCfg = logicMgr.MapManager.GetMapcfgByID(logicMgr.MapManager.getNextStage())
        formationsList.enemyData.name = string.format("关卡%s-%s", mapNextCfg.f_ChapterId, mapNextCfg.f_StageNum)
    end

    showUI(PanelNames.UITeamQuickchange, nil, function(data)
        if data ~= nil then
            for i = 1, self.formationsMax do
                for j = 1, 5 do
                    self.formations[i][j] = data[i].heroList[j].partnerId or "0"
                end
                self.helpManId[i] = data[i].heroList[6].partnerId or "0"
            end
        end
        self:initFormation()
        self:onClickItemIndex(self.formationsIndex)
        self:rendererFormation()
    end, formationsList, fightType)
end
--改变跳过按钮状态
function UIBattleTeam:onClickChangeSkipState(is)
    local someBattleSkip = logicMgr.ArenaManager.getSomeBattleSkip();
    logicMgr.ArenaManager.setSomeBattleSkip(not someBattleSkip);
    someBattleSkip = logicMgr.ArenaManager.getSomeBattleSkip();
    SetPlayerPrefs("TeamCrossSkip" .. logicMgr.HeroManager.GetRoleInfo("playerId"), someBattleSkip and 1 or 0);
    local str = someBattleSkip and "PVPSkipBtn_Text2" or "PVPSkipBtn_Text1";
    self.btnSkip:GetController("state").selectedIndex = someBattleSkip and 1 or 0;
    local msgStr = someBattleSkip and "PVPSkipBattle_Open" or "PVPSkipBattle_Close";
    UISysTips.AddMsg(getLanguage(msgStr));
    self.btnSkip:GetChild("title").text = getLanguage(str);
end

function UIBattleTeam:onClick_CloseTeamEditor()
    self.ctr_teamListShow.selectedIndex = 0
end

function UIBattleTeam:OnClickChallengeBtnAdd()
    if fightType ~= EnumConst.FightTypeConst.DarkStreet then
        return
    end
    local cost = dataTable.getGlobalString(546)
    local pop = CtrlManager.GetCtrl(PanelNames.UICommonPop);
    pop.Init("76", function(b)
        if b then
            logError("等待服务器接入")
        end
    end, cost[2], logicMgr.DarkStreetMgr.GetRemainBuyTimes(), cost[1]);
end
function UIBattleTeam:SetFriendBattleFormation()
    local heros = {}
    for i = 1, nodeCount + 1 do
        local config = self.tabHeroPosData[i]
        if i == 6 then
            config = self.helpMan[self.formationsIndex]
        end
        heros[i] = FriendBattleFormation.New()
        heros[i]["partner"] = PartnerInfo.New()
        heros[i]["partner"]["partnerModelId"] = (config and config.partnerModelId) and config.partnerModelId or 0
        heros[i]["partner"]["level"] = (config and config.level) and config.level or 0
        heros[i]["partner"]["star"] = (config and config.star) and config.star or 0
        heros[i]["partner"]["sameNum"] = 0
        heros[i]["partner"]["skinId"] = 0
        heros[i]["partner"]["fightVal"] = (config and config.power) and config.power or 0
        heros[i]["partner"]["fightVal2"] = (config and config.realPower) and config.realPower or 0
        heros[i]["partner"]["activateBondIds"] = {}
        heros[i]["partner"]["weaponLv"] = 0
        heros[i]["partner"]["weaponRank"] = config.weaponRank or 1
        heros[i]["partner"]["skinId"] = 0
        heros[i]["partner"]["favorLv"] = 0
        heros[i]["partner"]["favorExp"] = 0
        heros[i]["partner"]["favorRewardGetLv"] = 0
        heros[i]["partner"]["lastInteractTime"] = 0
        heros[i]["partner"]["interactInfos"] = {}
        local partnerId = config.partnerId
        if partnerId ~= 0 then
            heros[i]["partner"]["partnerId"] = partnerId and tostring(partnerId) or "0"
        else
            heros[i]["partner"]["partnerId"] = "0"
        end
        if self.playerIds[i] then
            heros[i]["playerId"] = tostring(self.playerIds[i])
        else
            heros[i]["playerId"] = "0"
        end
    end
    return heros;
end

function UIBattleTeam.onClickChapterReward()
    showUI(PanelNames.UIChapterRewardNew);
end

function UIBattleTeam:RefreshChapterRewardBtn()
    local itemModelId;
    local isEndLevel = logicMgr.MapManager.IsEndChapterMapId(MapManager.getMapId());
    local curChapter = logicMgr.MapManager.GetCurrentChapterId();
    local taskCfg;
    if isEndLevel then
        local hasReward, rewardGet = logicMgr.MapManager.GetChapterReward(MapManager.getMapId());
        local nextChapterTaskCfg = logicMgr.MapManager.GetChapterRewardCfg(curChapter + 1);
        if (hasReward and not rewardGet) or (nextChapterTaskCfg == nil) then
            --当前章节奖励未领取
            taskCfg = logicMgr.MapManager.GetChapterRewardCfg(curChapter);
            self.btnChapterRewardTips.text = "";
        else
            --显示下一章节奖励
            taskCfg = nextChapterTaskCfg;
            local maxMapCfg = MapManager.GetChapterMaxStageNum(curChapter + 1);
            self.btnChapterRewardTips.text = string.format(getLanguage("ChapterRewardText3"), maxMapCfg.f_StageNum);
        end
    else
        taskCfg = logicMgr.MapManager.GetChapterRewardCfg(curChapter);
        local curMapCfg = logicMgr.MapManager.getMapcfg();
        local maxMapCfg = MapManager.GetChapterMaxStageNum(curChapter);
        self.btnChapterRewardTips.text = string.format(getLanguage("ChapterRewardText3"), maxMapCfg.f_StageNum - curMapCfg.f_StageNum);
    end
    if taskCfg ~= nil and taskCfg.f_Award ~= nil and taskCfg.f_Award ~= "" then
        local reward = decodeJsonStrToTabel(taskCfg.f_Award)[1];
        if reward ~= nil then
            itemModelId = reward[1];
        end
    end
    if itemModelId ~= nil then
        UIComponentInterface:SetItemAllById(self.btnChapterRewardIcon, nil, nil, itemModelId);
    else
        self.btnChapterRewardIcon.url = "";
    end
end

function UIBattleTeam:GetHeroID()
    local Count = 0;
    for _, v in ipairs(self.tabHeroPosData) do
        if not v["partnerModelId"] then
            break ;
        else
            Count = Count + 1;
        end
    end
    return self.tabHeroPosData[math.random(1, Count)]
end

function UIBattleTeam:GetHeroType(modelId)
    local heroCfg = dataTable.getRow("t_hero", modelId)
    if heroCfg then
        return heroCfg["f_HeroType"]
    end
    return nil
end

function UIBattleTeam:initEnemyFormation()
    if self.otherSupSkill then
        local skillDataOther = G.dataTable["t_skillshow"][tostring(self.otherSupSkill)];
        if skillDataOther then
            self.supSkillRight:GetChild("icon"):GetChild("icon").url = "ui://SkillAtlas/" .. skillDataOther.f_SkillIcon
        end
    end
    local monsters = self.oppoFormations[self.formationsIndex]
    if monsters == nil or #monsters <= 0 then
        monsters = {}
        for i = 1, nodeCount do
            local item = {}
            item["partnerId"] = nil
            item["partnerModelId"] = nil
            table.insert(monsters, item)
        end
        self.enemyHelpManId[self.formationsIndex] = nil
        self.enemyHelpMan[self.formationsIndex] = { partnerModelId = nil, partnerId = nil }
    end
    self.tabMonsterPosData = {}
    if type(self.powerEnemyNum) == "table" then
        self.powerEnemy.text = getNumString(self.powerEnemyNum[self.formationsIndex])
    else
        self.powerEnemy.text = getNumString(self.powerEnemyNum)
    end

    for i = 1, nodeCount do
        local v = monsters[i]
        if i <= nodeCount then
            local info = {
                partnerModelId = "0",
                level = 1,
                icon = "",
                state = nil,
                teamIndex = 2,
                weaponLevel = nil,
                weaponRank = 1,
                site = i
            }
            if v ~= nil then
                info = {
                    partnerId = v["partnerId"],
                    partnerModelId = v["partnerModelId"],
                    level = v["level"] or 1,
                    star = v["star"],
                    type = self:GetHeroType(v["partnerModelId"]),
                    weaponLevel = v["weaponLevel"],
                    weaponRank = v["weaponRank"],
                    icon = "",
                    state = nil,
                    teamIndex = 2,
                    site = i,
                    skinId = v["skinId"]
                }
            end
            table.insert(self.tabMonsterPosData, info)
        end

    end
    if #self.tabMonsterPosData < nodeCount then
        for i = #self.tabMonsterPosData + 1, nodeCount do
            local info = {
                partnerModelId = "0",
                level = 1,
                icon = "",
                state = nil,
                teamIndex = 2,
                site = i
            }
            table.insert(self.tabMonsterPosData, info)

        end
    end
    local HelpInfo = {
        partnerModelId = "0",
        level = 1,
        icon = "",
        state = nil,
        teamIndex = 2,
        site = SUPPORT_TEAMMATE_SITE
    }
    if self.enemyHelpMan[self.formationsIndex] and self.enemyHelpManId[self.formationsIndex] ~= 0 then
        HelpInfo = {
            partnerId = self.enemyHelpMan[self.formationsIndex]["partnerId"],
            partnerModelId = self.enemyHelpMan[self.formationsIndex]["partnerModelId"],
            level = self.enemyHelpMan[self.formationsIndex]["level"] or 1,
            star = self.enemyHelpMan[self.formationsIndex]["star"],
            skinId = self.enemyHelpMan[self.formationsIndex]["skinId"],
            type = self:GetHeroType(self.enemyHelpMan[self.formationsIndex]["partnerModelId"]),
            icon = "",
            state = nil,
            teamIndex = 2,
            site = SUPPORT_TEAMMATE_SITE
        }
    end
    self.tabMonsterPosData[nodeCount + 1] = HelpInfo
    for i = 1, #self.tabMonsterPosData do
        local itemData = self.tabMonsterPosData[i]
        if itemData.partnerId ~= nil and tonumber(tostring(itemData.partnerId)) > 0 then
            self.rightBottoms[i].visible = true;
            local bIndex = Config.IconQualityBottom[logicMgr.HeroManager.starToQuality(itemData.star)]
            self.rightBottoms[i].url = "ui://ICONAtlas/" .. bIndex
        else
            self.rightBottoms[i].visible = false
        end
        local role = self.rightPos[itemData.site]
        --[[if self.ctrlIfMainBattle.selectedIndex == 5 and i==3 then
            role.parent:SetChildIndex(role,108)
        end--]]
        local type = self.isShowTitle and 1 or 0
        local ctrlItem = CtrlManager.GetCtrl(PanelNames.TeamHeroItem)
        if ctrlItem ~= nil then
            --初始人物信息
            role.visible = true
            --logicMgr.UIShowManager.getTeamHeroItem(itemData.teamIndex, i, self.titleNode)
            ctrlItem.initData(role, itemData, i, type, function(data, self)
                if not data.isEmpty then
                    self:showHeroEffect(data)
                    self:playUpFormationEffect(data);
                else
                    self:clearUpBattleEff(data);
                end
            end, fightType, nil, nodeCount + 1, self.formationType, self)
        end
    end
    if self.ctrlIfMainBattle.selectedIndex ~= 5 then
        --self.titleNode:GetChild("title27").visible = false
        --self.titleNode:GetChild("title28").visible = false
    end
end

function UIBattleTeam:showHeroEffect(data)
    if self.isInit then
        return
    end
    if data.teamId == 2 then
        return
    end
    local flag = false;
    if data.idx == 6 and (tonumber(self.lastHelpManId) == 0 or tonumber(self.lastHelpManId) == nil) then
        flag = true;
    elseif data.idx ~= 6 and self.lastFormationPosData[data.idx] == nil or (self.lastFormationPosData[data.idx] and (self.lastFormationPosData[data.idx].partnerModelId == nil or tonumber(self.lastFormationPosData[data.idx].partnerModelId) == 0)) then
        flag = true;
    end
    if flag then
        local heroRace = G.dataTable["t_hero"][tostring(data.modelId)]["f_FactionType"];
        if (heroRace ~= 1 and heroRace ~= 2 and heroRace ~= 3) then
            local ani = self.showHeroEffects[data.teamId][data.idx]
            ani.visible = true
            ani.spineAnimation.state:SetAnimation(0, "idle", false)
            local idleAniTime = ani.spineAnimation.state.Data.SkeletonData:FindAnimation("idle").Duration
            utimer.remove(self.effectTimers[data.teamId .. data.idx])
            local timer = utimer.timeCall(self.showEffectEnd, idleAniTime * 1000, 1)
            self.effectTimers[data.teamId .. data.idx] = timer
            table.insert(self.effectList, ani)
        end
    end
end

function UIBattleTeam.showEffectEnd()
    local self = UIBattleTeam;
    local endEffect = table.remove(self.effectList, 1)
    if endEffect and endEffect.visible then
        endEffect.visible = false
    end
end

function UIBattleTeam:RemoveEffect()
    self.effectList = {};
    for i, v in pairs(self.effectTimers) do
        utimer.remove(v)
    end
end

function UIBattleTeam:initFormation()
    if self.formationType == EnumConst.FightTypeConst.FriendDefend
            or self.formationType == EnumConst.FightTypeConst.FriendAttack
    then
        self.isFriendBattle = true;
        if self.formationType == EnumConst.FightTypeConst.FriendAttack then
            self:RefreshSkipState();
        end
        if not (self.playerIds and table.getn(self.playerIds) > 0) then
            self.playerIds = logicMgr.FriendBattleManager.GetPlayerIds(self.formationType)
        end
    else
        self.isFriendBattle = false
    end
    local tempDta = clone(self.tabHeroPosData)
    for i = 1, self.formationsMax do
        self.tabHeroPosDataTemp[i] = {}
        for j = 1, nodeCount do
            self.tabHeroPosDataTemp[i][j] = {}
        end
    end
    for j = 1, #self.formations do
        for i = 1, nodeCount do
            self.tabHeroPosDataTemp[j][i] = {}
        end
    end
    if not self.isChangTeam then
        self.lastHelpManId = self.helpMan[self.formationsIndex].partnerModelId;
    end
    self.lastFormationPosData = clone(self.tabHeroPosData) or {}
    for j = 1, #self.formations do
        local tempFormation = self.formations[j]
        if tempFormation ~= nil and table.getn(tempFormation) > 0 then
            for i = 1, nodeCount do
                --- 根据已保存的阵容恢复位置信息
                local partnerId = tempFormation[i]
                local isFind = false;
                if partnerId ~= nil then
                    if not (self.playerIds and self.playerIds[i] and tonumber(tostring(self.playerIds[i])) ~= 0) then
                        for k = 1, #self.tableHeros do
                            if tostring(partnerId) == tostring(self.tableHeros[k].partnerId) then
                                self.tabHeroPosDataTemp[j][i]["partnerId"] = self.tableHeros[k]["partnerId"]
                                self.tabHeroPosDataTemp[j][i]["partnerModelId"] = self.tableHeros[k]["partnerModelId"]
                                self.tabHeroPosDataTemp[j][i]["level"] = self.tableHeros[k]["level"]
                                self.tabHeroPosDataTemp[j][i]["star"] = self.tableHeros[k]["star"]
                                self.tabHeroPosDataTemp[j][i]["weaponLevel"] = self.tableHeros[k]["weaponLevel"]
                                self.tabHeroPosDataTemp[j][i]["icon"] = ""
                                self.tabHeroPosDataTemp[j][i]["type"] = self.tableHeros[k]["type"]
                                self.tabHeroPosDataTemp[j][i]["state"] = self.tableHeros[k]["state"]
                                self.tabHeroPosDataTemp[j][i]["power"] = self.tableHeros[k]["power"]
                                self.tabHeroPosDataTemp[j][i]["realPower"] = self.tableHeros[k]["realPower"]
                                self.tabHeroPosDataTemp[j][i]["site"] = i
                                self.tabHeroPosDataTemp[j][i]["weaponRank"] = logicMgr.HeroManager.GetWeaponQuality(self.tableHeros[k]["partnerModelId"])
                                isFind = true;
                                break ;
                            end
                        end
                        if not isFind then
                            for lk = 1, #self.tableLeaseHeros do
                                if tostring(partnerId) == tostring(self.tableLeaseHeros[lk].partnerId) then
                                    self.tabHeroPosDataTemp[j][i]["partnerId"] = self.tableLeaseHeros[lk]["partnerId"]
                                    self.tabHeroPosDataTemp[j][i]["partnerModelId"] = self.tableLeaseHeros[lk]["partnerModelId"]
                                    self.tabHeroPosDataTemp[j][i]["level"] = self.tableLeaseHeros[lk]["level"]
                                    self.tabHeroPosDataTemp[j][i]["star"] = self.tableLeaseHeros[lk]["star"]
                                    self.tabHeroPosDataTemp[j][i]["weaponLevel"] = self.tableLeaseHeros[lk]["weaponLevel"]
                                    self.tabHeroPosDataTemp[j][i]["icon"] = ""
                                    self.tabHeroPosDataTemp[j][i]["type"] = self.tableLeaseHeros[lk]["type"]
                                    self.tabHeroPosDataTemp[j][i]["state"] = self.tableLeaseHeros[lk]["state"]
                                    self.tabHeroPosDataTemp[j][i]["power"] = self.tableLeaseHeros[lk]["power"]
                                    self.tabHeroPosDataTemp[j][i]["realPower"] = self.tableLeaseHeros[lk]["realPower"]
                                    self.tabHeroPosDataTemp[j][i]["site"] = i
                                    self.tabHeroPosDataTemp[j][i]["weaponRank"] = 1;
                                    break ;
                                end
                            end
                        end
                    else
                        if self.isFriendBattle and partnerId then
                            local config = tempDta[i]
                            if not tempDta[i] then
                                config = logicMgr.FriendBattleManager.GetHerobyIndex(i, self.formationType)
                            end
                            if config and config.partnerModelId then
                                self.tabHeroPosDataTemp[j][i]["partnerId"] = config["partnerId"]
                                self.tabHeroPosDataTemp[j][i]["partnerModelId"] = config["partnerModelId"]
                                self.tabHeroPosDataTemp[j][i]["level"] = config["level"]
                                self.tabHeroPosDataTemp[j][i]["star"] = config["star"]
                                self.tabHeroPosDataTemp[j][i]["weaponLevel"] = config["weaponLevel"]
                                self.tabHeroPosDataTemp[j][i]["type"] = config["type"]
                                self.tabHeroPosDataTemp[j][i]["power"] = config["power"]
                                self.tabHeroPosDataTemp[j][i]["realPower"] = 0
                                self.tabHeroPosDataTemp[j][i]["realPower"] = 0;
                                self.tabHeroPosDataTemp[j][i]["name"] = config["name"]
                                self.tabHeroPosDataTemp[j][i]["icon"] = ""
                                self.tabHeroPosDataTemp[j][i]["site"] = i
                                self.tabHeroPosDataTemp[j][i]["weaponRank"] = logicMgr.HeroManager.GetWeaponQuality(config["partnerModelId"])
                            end
                        end
                    end
                end
            end
        end
        if tonumber(self.helpManId[j]) ~= 0 then
            if not (self.playerIds and self.playerIds[6] and tonumber(tostring(self.playerIds[6])) ~= 0) then
                local isFind = false;
                for k = 1, #self.tableHeros do
                    if tostring(self.helpManId[j]) == tostring(self.tableHeros[k].partnerId) then
                        self.helpMan[j]["partnerId"] = self.tableHeros[k]["partnerId"]
                        self.helpMan[j]["partnerModelId"] = self.tableHeros[k]["partnerModelId"]
                        self.helpMan[j]["level"] = self.tableHeros[k]["level"]
                        self.helpMan[j]["star"] = self.tableHeros[k]["star"]
                        self.helpMan[j]["weaponLevel"] = self.tableHeros[k]["weaponLevel"]
                        self.helpMan[j]["icon"] = ""
                        self.helpMan[j]["type"] = self.tableHeros[k]["type"]
                        self.helpMan[j]["state"] = self.tableHeros[k]["state"]
                        self.helpMan[j]["power"] = self.tableHeros[k]["power"]
                        self.helpMan[j]["realPower"] = self.tableHeros[k]["realPower"]
                        self.helpMan[j]["site"] = SUPPORT_TEAMMATE_SITE
                        self.helpMan[j]["weaponRank"] = logicMgr.HeroManager.GetWeaponQuality(self.tableHeros[k]["partnerModelId"])
                        isFind = true;
                        break ;
                    end
                end
                if not isFind then
                    for lk = 1, #self.tableLeaseHeros do
                        if tostring(self.helpManId[j]) == tostring(self.tableLeaseHeros[lk].partnerId) then
                            self.helpMan[j]["partnerId"] = self.tableLeaseHeros[lk]["partnerId"]
                            self.helpMan[j]["partnerModelId"] = self.tableLeaseHeros[lk]["partnerModelId"]
                            self.helpMan[j]["level"] = self.tableLeaseHeros[lk]["level"]
                            self.helpMan[j]["star"] = self.tableLeaseHeros[lk]["star"]
                            self.helpMan[j]["weaponLevel"] = self.tableLeaseHeros[lk]["weaponLevel"]
                            self.helpMan[j]["icon"] = ""
                            self.helpMan[j]["type"] = self.tableLeaseHeros[lk]["type"]
                            self.helpMan[j]["state"] = self.tableLeaseHeros[lk]["state"]
                            self.helpMan[j]["power"] = self.tableLeaseHeros[lk]["power"]
                            self.helpMan[j]["realPower"] = self.tableLeaseHeros[lk]["realPower"]
                            self.helpMan[j]["site"] = SUPPORT_TEAMMATE_SITE
                            self.helpMan[j]["weaponRank"] = 1;
                            break ;
                        end
                    end
                end
            else
                if self.isFriendBattle then
                    if self.helpMan[j]["partnerId"] and int64ToNumber(self.helpMan[j]["partnerId"]) ~= 0 then
                        self.helpMan[j] = self.helpMan[j]
                    else
                        local config = logicMgr.FriendBattleManager.GetHerobyIndex(6, self.formationType)
                        if config then
                            self.helpMan[j]["partnerId"] = config["partnerId"]
                            self.helpMan[j]["partnerModelId"] = config["partnerModelId"]
                            self.helpMan[j]["level"] = config["level"]
                            self.helpMan[j]["star"] = config["star"]
                            self.helpMan[j]["weaponLevel"] = config["weaponLevel"]
                            self.helpMan[j]["type"] = config["type"]
                            self.helpMan[j]["power"] = config["power"]
                            self.helpMan[j]["realPower"] = 0
                            self.helpMan[j]["name"] = config["name"]
                            self.helpMan[j]["icon"] = ""
                            self.helpMan[j]["site"] = SUPPORT_TEAMMATE_SITE
                            self.helpMan[j]["weaponRank"] = logicMgr.HeroManager.GetWeaponQuality(config["partnerModelId"])
                        end
                    end
                end
            end
        else
            self.helpMan[j] = {}
        end
    end
    self.tabHeroPosData = self.tabHeroPosDataTemp[self.formationsIndex]
    tempDta = nil
    if self.isFriendBattle then
        logicMgr.FriendBattleManager.BattleTeam(self.tabHeroPosData, self.helpMan[self.formationsIndex])
    end
end

function UIBattleTeam:refreshPower()
    local powerNum = 0;
    if fightType == EnumConst.FightTypeConst.ARENA and param ~= nil and param.arena_type == EnumConst.ArenaBattleType.TeamCross then
        for k = 1, #self.tabHeroPosData do
            local localPartnerId = self.tabHeroPosData[k]["partnerId"];
            if localPartnerId ~= nil and tostring(localPartnerId) ~= "0" then
                powerNum = powerNum + logicMgr.HeroManager.CalcHeroPowerWithLv(localPartnerId, 300);
            end
        end
    else
        for i = 1, #self.tabHeroPosData do
            if self.tabHeroPosData[i]["power"] ~= nil then
                powerNum = powerNum + self.tabHeroPosData[i]["power"];
            end
        end
    end

    if self.helpMan then
        if not self.isFriendBattle then
            local hero = logicMgr.HeroManager.getHeroDatabyPartnerId(self.helpMan[self.formationsIndex].partnerId, true)
            if hero then
                if fightType == EnumConst.FightTypeConst.ARENA and param ~= nil and param.arena_type == EnumConst.ArenaBattleType.TeamCross then
                    powerNum = powerNum + logicMgr.HeroManager.CalcHeroPowerWithLv(self.helpMan[self.formationsIndex].partnerId, 300);
                else
                    powerNum = powerNum + hero.power
                end
            else
                if fightType == EnumConst.FightTypeConst.DUNGEON then
                    if self.helpMan[self.formationsIndex].power ~= nil then
                        powerNum = powerNum + self.helpMan[self.formationsIndex].power;
                    end
                end
            end
        end
    end

    self.power.text = getNumString(powerNum)
end

--模型显示
function UIBattleTeam:rendererFormation()
    self:refreshPower();
    self.isShowChoose = nil;
    for i = 1, #self.tabHeroPosData do
        if nodeCount >= i then
            local role = self.leftRole[i]
            --[[if self.ctrlIfMainBattle.selectedIndex == 5 and i==3 then
                role.parent:SetChildIndex(role,91)
            end--]]
            local pos = self.leftRect[i]
            if role.dragBounds == nil or role.dragBounds.y ~= self.leftGroup.y then

                role.dragBounds = UnityEngine.Rect.New(self.leftGroup.x + Config.uiXOffset, self.leftGroup.y, self.leftGroup.actualWidth + Config.uiXOffset, self.leftGroup.actualHeight);
            end
            role.draggable = true
            role:SetPosition(pos.x, pos.y, 0)

            local itemData = self.tabHeroPosData[i]
            if itemData.partnerId ~= nil then
                self.leftBottoms[i].visible = true
                local bIndex = nil
                if self.formationType == EnumConst.FightTypeConst.RankBattle then
                    bIndex = Config.IconQualityBottom[15]
                else
                    bIndex = Config.IconQualityBottom[Mathf.Floor(itemData.star / 10)]
                end
                self.leftBottoms[i].url = "ui://ICONAtlas/" .. bIndex
            else
                self.leftBottoms[i].visible = false
            end
            local ctrlItem = CtrlManager.GetCtrl(PanelNames.TeamHeroItem)
            local type = self.isShowTitle and 1 or 0
            if ctrlItem ~= nil then
                --初始装备信息
                --logicMgr.UIShowManager.getTeamHeroItem(itemData.teamIndex, i, self.titleNode)
                ctrlItem.initData(role, itemData, i, type, function(data, self)
                    if not data.isEmpty then
                        self:showHeroEffect(data)
                        self:playUpFormationEffect(data);
                    else
                        self:clearUpBattleEff(data);
                    end
                end, fightType, self.isShowDebris, nodeCount + 1, self.formationType, self);
                self.isShowChoose = self.isShowChoose or self:isShowChooseHero(itemData, ctrlItem);
            end
            if self.tabHeroPosData[i].partnerId == nil then
                role.draggable = false
            else
                role.draggable = true
            end
        end
    end

    local role = self.leftRole[nodeCount + 1]
    local pos = self.leftRect[nodeCount + 1]
    if role.dragBounds == nil or role.dragBounds.y ~= self.leftGroup.y then
        role.dragBounds = UnityEngine.Rect.New(self.leftGroup.x, self.leftGroup.y, self.leftGroup.actualWidth, self.leftGroup.actualHeight);
    end
    role.draggable = true
    role:SetPosition(pos.x, pos.y, 0)
    local itemData = self.helpMan[self.formationsIndex]
    if itemData.partnerId ~= nil then
        self.leftBottoms[nodeCount + 1].visible = true;
        local bIndex = nil
        if self.formationType == EnumConst.FightTypeConst.RankBattle then
            bIndex = Config.IconQualityBottom[15];
        else
            bIndex = Config.IconQualityBottom[Mathf.Floor(itemData.star / 10)]
        end
        self.leftBottoms[nodeCount + 1].url = "ui://ICONAtlas/" .. bIndex
    else
        self.leftBottoms[nodeCount + 1].visible = false
    end
    local ctrlItem = CtrlManager.GetCtrl(PanelNames.TeamHeroItem)
    local type = self.isShowTitle and 1 or 0

    if ctrlItem ~= nil then
        --初始装备信息
        --logicMgr.UIShowManager.getTeamHeroItem(itemData.teamIndex, nodeCount + 1, self.titleNode)
        ctrlItem.initData(role, itemData, nodeCount + 1, type, function(data, self)
            if not data.isEmpty then
                self:showHeroEffect(data)
                self:playUpFormationEffect(data);
            else
                self:clearUpBattleEff(data);
            end
        end, fightType, self.isShowDebris, nodeCount + 1, self.formationType, self);
        self.isShowChoose = self.isShowChoose or self:isShowChooseHero(itemData, ctrlItem);
    end
    if self.ctrlIfMainBattle.selectedIndex ~= 5 then
        --self.titleNode:GetChild("title17").visible = false
        --self.titleNode:GetChild("title18").visible = false
    end
    if self.helpMan[self.formationsIndex].partnerId == nil then
        role.draggable = false
    else
        role.draggable = true
    end
    self.heroTacticsController.selectedIndex = self.isShowChoose and 1 or 0;
end

function UIBattleTeam:isShowChooseHero(itemData)
    if itemData == nil or itemData.partnerId == nil then
        return ;
    end
    if not logicMgr.HeroManager.isShowChooseByType(self.formationType) or fightType == EnumConst.FightTypeConst.FormationEditor then
        return ;
    end
    if self.formationType == EnumConst.FormationType.RankBattle then
        return logicMgr.SkillManager.getNeedChooseHeroById(itemData.partnerModelId, 300, logicMgr.HeroManager.starToQuality(itemData.star))
    else
        return logicMgr.SkillManager.getNeedChooseHeroById(itemData.partnerModelId, itemData.level, logicMgr.HeroManager.starToQuality(itemData.star))
    end
end

function UIBattleTeam:onClickItemIndex(index)

    self.formationsIndex = index
    if self.formationsIndex < 1 then
        self.formationsIndex = 1
    end
    if self.formationsIndex > self.formationsMax then
        self.formationsIndex = self.formationsMax
    end
    for i = 1, self.formationsMax do
        if self.formations[i] ~= nil and self.helpManId[i] ~= 0 then
            self.formations[i][nodeCount + 1] = self.helpManId[i]
        end
    end
    for k, v in pairs(self.tableFormationIndex) do
        local selCtrl = v:GetController("select")
        if selCtrl then
            if index == k then
                selCtrl.selectedIndex = 1
            else
                selCtrl.selectedIndex = 0
            end
        end
    end
    self.clearController:SetSelectedIndex(0)
    if fightType == EnumConst.FightTypeConst.DUNGEON or fightType == EnumConst.FightTypeConst.StoryBattle then
        local data = logicMgr.BattlePlaybackManager.GetGroupBossHistory(self.formationsIndex);
        if data and data.record and data.record.win == 1 then
            self.clearController:SetSelectedIndex(1)
        end
    elseif fightType == EnumConst.FightTypeConst.GuildBattlePlus then
        if param.formationIsOver and param.formationIsOver[self.formationsIndex] then
            self.clearController:SetSelectedIndex(1)
        end
    end
    self:initFormation()
    self:rendererFormation()
    self:initEnemyFormation()
    self:onClickType()
    self:RefreshBossBtn()
    self:refreshCombinationSkill();
end

function UIBattleTeam:createFormation()
    local formation = {}
    if #self.formations > 1 then
        for j = 1, #self.formations do
            for i = 1, #self.tabHeroPosDataTemp[j] do
                if formation[j] == nil then
                    formation[j] = {}
                end
                if self.tabHeroPosDataTemp[j][i]["partnerId"] ~= nil and tonumber(self.tabHeroPosDataTemp[j][i]["partnerId"]) > 0 then
                    table.insert(formation[j], self.tabHeroPosDataTemp[j][i]["partnerId"])
                else
                    table.insert(formation[j], "0")
                end
            end
        end
    end
    return formation
end

-- 英雄是否在阵容中（是否检查当前设置的阵容）
function UIBattleTeam:isInFormations(partnerId, checkCurFormation)
    for i = 1, #self.formations do
        if i ~= self.formationsIndex or checkCurFormation then
            for k = 1, #self.formations[i] do
                if self.formations[i][k] == partnerId then
                    return true
                end
            end
        end
    end
    return false
end

function UIBattleTeam:refreshFormation()
    local self = UIBattleTeam
    local formation = logicMgr.FormationManager.GetFormation(EnumConst.FormationType.Duplicate)
    self.formations[self.formationsIndex] = {}
    if formation ~= nil then
        for k, v in pairs(formation) do
            if k == nodeCount + 1 then
                self.helpManId[self.formationsIndex] = tostring(v)
            else
                self.formations[self.formationsIndex][k] = tostring(v)
            end
            local state = EnumConst.HeroHeadStateEnum.BATTLE
            for i = 1, #self.tableHeros do
                if tostring(self.helpManId[self.formationsIndex]) == tostring(self.tableHeros[i].partnerId) then
                    local data = logicMgr.HeroManager.setHeroState(self.tableHeros[i].partnerId, true, state, self.formationType, self.tableHeros[i])
                    self.tableHeros[i]["state"] = data["state"]
                end
                if self.tableHeros[i].partnerId == tostring(v) then
                    local data = logicMgr.HeroManager.setHeroState(self.tableHeros[i].partnerId, true, state, self.formationType, self.tableHeros[i])
                    self.tableHeros[i]["state"] = data["state"]
                end
            end
        end
    end

    self:onClickType(true, self.curTabType)
    self:initFormation()
    self:rendererFormation()
    self:initEnemyFormation()
end

function UIBattleTeam:TouchAnyKeyMsg()
end

--引导移动
function UIBattleTeam:GuideTeamRoleTouch(name, index, _end)
    local role = self.leftRole[index]
    if not role then
        return
    end
    if name == "begin" then
        role:StartDrag()
    elseif name == "end" then
        role:StopDrag()
        if isIntersect(self.leftRect[_end], role) then
            FireEvent(Config.EventType.GuideTeamRoleTouchSuc)
        else
            _end = index
        end
        self:changePosByIndex(index, _end)
        role:SetPosition(self.leftRect[index].x, self.leftRect[index].y, 0)
        if (index ~= 0) then
            role.parent:SetChildIndex(role, self.leftIndex[index])
        end
    end
end

--引导查找heroId
function UIBattleTeam:GuideFindHeroIdMsg(heroId)
    if self.tabOwner == nil or #self.tabOwner == 0 then
        return
    end

    local sortFunc = HeroManager.getSortHeroByType()
    table.sort(self.tabOwner, function(a, b)
        local aw = a.partnerModelId == heroId and 10 or 0
        local bw = b.partnerModelId == heroId and 10 or 0
        if aw ~= bw then
            return aw > bw
        end
        return sortFunc(a, b)
    end)
    self.dynamicList.numItems = #self.tabOwner
    self.dynamicList:ScrollToView(0)
    for k, v in pairs(self.tabOwner) do
        if v.partnerModelId == tostring(heroId) then
            local item = self.dynamicList:GetChildAt(k - 1)
            FireEvent(Config.EventType.GuideFindHeroIdSuc, item)
            return
        end
    end
    logError("[引导]找不到节点,heroId  " .. heroId)
end

--职业爬塔限定能够选到的英雄类型（英雄类型按钮置灰）
function UIBattleTeam:AdvancedTowerDisableBtn()
    for k, v in pairs(self.occupationBtns) do
        v.grayed = true
    end
    local canSelectHeroTypes = logicMgr.TowerManager.getAdvancedTowerHeroType()
    for k, v in pairs(canSelectHeroTypes) do
        for m, n in pairs(self.occupationBtns) do
            local occupationType = tonumber(string.split(n.name, "_")[2]) or 0
            if occupationType == v then
                n.grayed = false
            end
        end
    end
end

--激活英雄职业类型按钮
function UIBattleTeam:EnableHeroTypeBtn()
    for k, v in pairs(self.occupationBtns) do
        v.grayed = false
    end
end

--刷新羁绊技能
function UIBattleTeam:refreshCombinationSkill()
    local formationList = {};
    local enemyFormationList = {};
    for i, v in pairs(self.tabHeroPosData) do
        if v and v.partnerModelId and tonumber(v.partnerModelId) ~= 0 then
            local modelId = v.partnerModelId;
            table.insert(formationList, modelId)
        end
    end
    local modelId = self.helpMan[self.formationsIndex].partnerModelId;
    if modelId and tonumber(modelId) ~= 0 and not self.isFriendBattle then
        table.insert(formationList, modelId)
    end
    if self.oppoFormations[self.formationsIndex] then
        for i, v in pairs(self.oppoFormations[self.formationsIndex]) do
            if v and v.partnerModelId and tonumber(v.partnerModelId) ~= 0 then
                local modelEnemyId = v.partnerModelId;
                table.insert(enemyFormationList, modelEnemyId)
            end
        end
        local modelEnemyId = self.enemyHelpMan[self.formationsIndex].partnerModelId;
        if modelEnemyId and tonumber(modelEnemyId) ~= 0 and not self.isFriendBattle then
            table.insert(enemyFormationList, modelEnemyId)
        end
    end

    self.combinationListInfo = HeroManager.getCombinationSkillList(formationList);
    self.combinationListInfoEnemy = HeroManager.getCombinationSkillList(enemyFormationList);
    self.combinationListBgCtrl.selectedIndex = table.getn(self.combinationListInfo) > 0 and 1 or 0;

    local isPvE = FightManager.checkIsFightTypePVE(fightType);
    if not isPvE then
        self.combinationListEnemy.visible = true;
        self.combinationListEnemyBgCtrl.selectedIndex = table.getn(self.combinationListInfoEnemy) > 0 and 1 or 0;
        self.combinationListEnemy.numItems = table.getn(self.combinationListInfoEnemy);
    else
        if fightType ~= EnumConst.FightTypeConst.TRIAL then
            self.combinationListEnemy.visible = false;
            self.combinationListEnemyBgCtrl.selectedIndex = 0;
        end
    end
    self.combinationList.numItems = table.getn(self.combinationListInfo);

end

function UIBattleTeam:rendererCombinationSkillItem(idx, obj, listInfo, type)
    local data = listInfo[idx + 1];
    local cfg = HeroManager.getCombinationInfo();
    local nameText = obj:GetChild("title");
    local iconImg = obj:GetChild("icon");
    local typeCtrl = obj:GetController("type");
    iconImg.url = "ui://SkillAtlas/" .. cfg[tostring(data.skillId)].f_CombinationIcon;
    nameText.text = getLanguage(cfg[tostring(data.skillId)].f_CombinationName);
    typeCtrl.selectedIndex = type;
    obj.onClick:Clear();
    obj.onClick:Add(function()
        self.combinationComCtrl.selectedIndex = 1;
        self:onShowComb(data);
    end)
end

function UIBattleTeam:onShowComb(heroData)
    local heroList = self.combinationCom:GetChild("hero");
    local ctrl = self.combinationCom:GetController("state");
    local cfg = HeroManager.getCombinationInfo()[tostring(heroData.skillId)];
    if table.getn(cfg.f_CombinationFaction) == 0 then
        ctrl.selectedIndex = 0;
        heroList.itemRenderer = function(idx, obj)
            self:rendererHero(idx + 1, obj, heroData);
        end
        heroList.numItems = table.getn(heroData.heroIds);

    else
        ctrl.selectedIndex = 1;
        local desText2 = self.combinationCom:GetChild("Describe2");
        desText2.text = getLanguage(cfg.f_CombinationDesc);
    end

    local desText = self.combinationCom:GetChild("Describe");
    desText.text = getLanguage(heroData.decs);

    local skillNameText = self.combinationCom:GetChild("title");
    skillNameText.text = getLanguage(cfg.f_CombinationName);

    local iconImg = self.combinationCom:GetChild("icon");
    iconImg.url = "ui://SkillAtlas/" .. cfg.f_CombinationIcon;

end

function UIBattleTeam:rendererHero(idx, obj, info)
    local charactor = CtrlManager.GetCtrl(PanelNames.HeadRectItem);
    --local ctrl = itemobj:GetTransition("Effect_List")
    --ctrl:Play()
    local hero = info.heroIds[idx];
    if charactor ~= nil then
        --初始英雄信息
        local heroData = {};
        logicMgr.HeroManager.copyHeroConfigbyModelId(hero, heroData);

        if heroData then
            charactor.initData(obj, heroData, nil, nil, nil, nil, nil, nil, true);
            obj.touchable = false;
        end
    end
end

function UIBattleTeam.GetMapName()
    if mapName ~= nil and mapName ~= "" then
        return "Prefabs/MapPref/" .. mapName
    end

    return nil
end

--function UIBattleTeam:SetBgType1()
--    mapName = logicMgr.MapManager.GetMapNameByFightType(fightType)
--    if mapName == nil then return end
--    local mapPos = decodeJsonStrToTabel(G.dataTable["t_mappos"][mapName]["f_MapPos"]) or {};
--    resMgr:LoadMapPrefab("Prefabs/MapPref/"..mapName, function(obj)
--        self.mapObj = newObject(obj)
--        local battleMap = self.mapObj.transform:Find("BattleMap")
--        if battleMap then
--            Util.Lua_SetLocalPositionXYZ(battleMap, mapPos[1], mapPos[2], mapPos[3]);
--            Util.Lua_SetLocalScaleXYZ(battleMap, 0.5, 0.5, 0.5);
--            Util.Lua_SetLocalRotationXYZ(battleMap, -40, 0, 0);
--            battleMap.gameObject:SetActive(true)
--            Util.SetLayerMask(battleMap.gameObject,"UI",true);
--        end
--    end)
--end

function UIBattleTeam:SetBgType()
    mapName = logicMgr.MapManager.GetMapNameByFightType(fightType)
    if mapName == nil then
        return
    end
    local mapPos = decodeJsonStrToTabel(G.dataTable["t_mappos"][mapName]["f_MapPos"]) or {};
    resMgr:LoadMapPrefab("Prefabs/MapPref/" .. mapName, function(obj)
        if self.goWrapper == nil then
            self.goWrapper = GoWrapper.New();
        end
        if self.mapObj ~= nil then
            destroyImmediate(self.mapObj);
        end
        self.mapObj = newObject(obj)
        self.mapObj:SetActive(true)
        local battleMap = self.mapObj.transform:Find("BattleMap")
        local Map = self.mapObj.transform:Find("Map")
        Map.gameObject:SetActive(false)
        self.goWrapper:SetWrapTarget(self.mapObj, false)
        self.mapHolder:SetNativeObject(self.goWrapper)
        Util.Lua_SetLocalPositionXYZ(battleMap, mapPos[1], mapPos[2], mapPos[3]);
        Util.Lua_SetLocalScaleXYZ(battleMap, 130, 130, 130);
        Util.Lua_SetLocalRotationXYZ(battleMap, -40, 0, 0);
    end)
end

--暗巷时间
function UIBattleTeam:RefreshDarkStreetTime()
    if fightType ~= EnumConst.FightTypeConst.DarkStreet then
        return
    end
    if not self.darkStreetTimerId then
        self.darkStreetTimerId = self:TimeCall(self.RefreshDarkStreetTime, 1000, -1)
    end
    local OpenStage = RedRob.Config.OpenStage
    local stage, remainTime = logicMgr.DarkStreetMgr.GetOpenStage()
    if stage == OpenStage.open or stage == OpenStage.waiting then
        self.Text_NextDarkStreet.text = string.format(getLanguage("DarkLaneTipes_45"), HelperFunc.GetMinuteSecond(remainTime))
        --self.Text_NextDarkStreet.text = string.format(getLanguage("DarkStreetTimeTips2"),HelperFunc.GetMinuteSecond(remainTime))
        --elseif stage == OpenStage.waiting then
        --self.Text_NextDarkStreet.text = string.format(getLanguage("DarkStreetTimeTips1"),HelperFunc.GetMinuteSecond(remainTime))
    else
        self.Text_NextDarkStreet.text = string.format(getLanguage("DarkLaneTipes_44"))
    end
end
--暗巷挑战次数
function UIBattleTeam:RefreshDarkStreetChallengeTimes()
    if fightType ~= EnumConst.FightTypeConst.DarkStreet then
        return
    end
    self.Text_DarkStreetChallenge.visible = false
    self.Btn_Add.visible = false
    --self.Text_DarkStreetChallenge.text = string.format(getLanguage("DarkStreetChallengeTips"),logicMgr.DarkStreetMgr.GetRemainTimes())
end
----------------------- 编队 start


function UIBattleTeam:CampareFormation(tb)
    local skill = SkillManager.getSupSkillIdByFormationType(self.formationType)
    if skill ~= tb.skill then
        return false
    end

    return CompareTable(tb.team, self.formations[self.formationsIndex])
end

--选择预设编队
function UIBattleTeam:SelectTeam(index)
    logicMgr.FormationManager.SetFocus(index + 1)
    m_record_force_list = {}

    m_choose_team = index + 1
    local preType = self.formationType

    local tb = FormationManager.GetEditorTeam(index + 1)

    if self:CampareFormation(tb) then
        UISysTips.AddMsg(getLanguage("UIBattleManyTeams1013"))
        return
    end

    local cur_team = self.formationsIndex
    if self.formations[cur_team] == nil then
        self.formations[cur_team] = {}
    end
    if tb then
        local temp = {}
        if self.formationsMax > 1 then
            local lst = clone(tb.team)

            for i = 1, self.formationsMax do
                if i ~= cur_team then
                    for j = 1, 6 do
                        if self.formations[i][j] and self.formations[i][j] ~= "0" then
                            local re = nil
                            for kk, pid in pairs(lst) do
                                if pid ~= "0" and pid == self.formations[i][j] then
                                    table.insert(temp, pid)
                                    re = kk
                                    break
                                end
                            end
                            if re then
                                table.remove(lst, re)
                            end
                        end
                    end
                end
            end
        end

        if table.getn(temp) > 0 then
            local cb1 = function()
                for i = 1, self.formationsMax do
                    for j = 1, 6 do
                        for k, v in pairs(temp) do
                            if i ~= cur_team then
                                if self.formations[i][j] == v then
                                    table.insert(m_record_force_list, self.formations[i][j])
                                    self.formations[i][j] = "0"
                                    break
                                end
                            end
                        end
                    end
                end

                for i = 1, 6 do
                    self.formations[cur_team][i] = tb.team[i]
                end
                self:FilterFormation()
                self:OnFormationChanged()
            end

            local cb2 = function()
                local b = false
                for i = 1, 6 do
                    b = false
                    for k, v in pairs(temp) do
                        if tb.team[i] == v then
                            b = true
                        end
                    end
                    if b then
                        self.formations[cur_team][i] = "0"
                    else
                        self.formations[cur_team][i] = tb.team[i]
                    end
                end
                self:FilterFormation()
                self:OnFormationChanged()
            end

            self:ShowTeamCommonPop(cb1, cb2)
        else
            for i = 1, 6 do
                self.formations[cur_team][i] = tb.team[i]
            end

            self:FilterFormation()
            self:OnFormationChanged()
        end
    end

    if tb.skill ~= 0 and m_current_show_skill ~= tb.skill then
        skillHandler.SendReqSelectAssistantSkillMessage(tb.skill, preType)
        m_current_show_skill = tb.skill
    else
        m_current_show_skill = tb.skill
    end

    self.ctr_teamListShow.selectedIndex = 0
end

function UIBattleTeam:FilterFormation()
    local havecant = false--是否有不可上阵，职业限制或死亡状态
    local cur_team = self.formationsIndex
    if fightType == EnumConst.FightTypeConst.TOWER then
        --职业过滤
        local curTowerType = logicMgr.TowerManager.getClimbType()
        --职业爬塔
        if G.dataTable["t_towertype"][tostring(curTowerType)].f_Group == EnumConst.TowerType.Advanced then
            local canSelectHeroTypes = logicMgr.TowerManager.getAdvancedTowerHeroType()
            local limit = {}
            for k, v in pairs(canSelectHeroTypes) do
                limit[v] = v
            end

            local lss = self.formations[cur_team]

            for k = 1, #lss do
                if tostring(lss[k]) ~= "0" then
                    local h = HeroManager.getHeroDatabyPartnerId(lss[k])
                    if not limit[h.type] then
                        lss[k] = "0"
                        havecant = true
                    end
                end
            end
        end
    else
        local lss = self.formations[cur_team]
        for k = 1, #lss do
            --死亡状态过滤
            if tostring(lss[k]) ~= "0" then
                local h = HeroManager.getHeroDatabyPartnerId(lss[k])
                if h.state == EnumConst.HeroHeadStateEnum.DEAD then
                    --UISysTips.AddMsg(getLanguage("DefendRedTips")) 
                    lss[k] = "0"
                    havecant = true
                end
            end
        end
    end

    local h
    if self.formationType ~= 57 and not self.isFriendBattle and fightType ~= EnumConst.FightTypeConst.DarkStreet then
        --默认300级跳过
        if havecant then
            UISysTips.AddMsg(getLanguage("UIBattleManyTeams1015"))
        else
            for k, v in pairs(self.formations[cur_team]) do
                if v ~= "0" then
                    local level = logicMgr.HeroManager.getHeroShowLevelByPartnerId(tostring(v));
                    if tonumber(level) == 1 then
                        UISysTips.AddMsg(getLanguage("DefendRedTips"))
                        break
                    end
                end
            end
        end
    end
end

function UIBattleTeam:OnFormationChanged()
    local state = EnumConst.HeroHeadStateEnum.BATTLE

    local ft = self.formations[self.formationsIndex]
    self.helpManId[self.formationsIndex] = ft[6]--支援角色处理
    for k, v in pairs(self.helpManId) do
        if k ~= self.formationsIndex then
            for kk, vv in pairs(ft) do
                if v == vv then
                    self.helpManId[k] = "0"
                    break
                end
            end
        end
    end

    -- if ft[6] ~= "0" then
    --     self.helpMan[self.formationsIndex] = HeroManager.getHeroDatabyPartnerId(ft[6])
    -- end

    for k, v in pairs(self.tableHeros) do
        if v.state == EnumConst.HeroHeadStateEnum.BATTLE then
            v.state = 0
        elseif v.state == EnumConst.HeroHeadStateEnum.USED and fightType == EnumConst.FightTypeConst.DUNGEON then
            v.state = 0
        end
    end
    for k, v in pairs(self.tabOwner) do
        if v.state == EnumConst.HeroHeadStateEnum.BATTLE then
            v.state = 0
        end
    end
    for lk, lv in pairs(self.tableLeaseHeros) do
        lv.state = 0
    end

    local temp_battle_list = {}
    local templist = {}
    for i = 1, self.formationsMax do
        if i ~= self.formationsIndex then
            for j = 1, 6 do
                if self.formations[i][j] and tostring(self.formations[i][j]) ~= "0" then
                    table.insert(templist, self.formations[i][j])

                    temp_battle_list[self.formations[i][j]] = state
                end
            end
        else
            for j = 1, 6 do
                if ft[j] ~= "0" then
                    table.insert(templist, ft[j])
                    temp_battle_list[ft[j]] = state
                end
            end
        end
    end

    for u = 1, #self.tableHeros do
        if temp_battle_list[tostring(self.tableHeros[u].partnerId)] then
            local data = logicMgr.HeroManager.setHeroState(self.tableHeros[u].partnerId, true, state, self.formationType, self.tableHeros[u])
            self.tableHeros[u]["state"] = data["state"]
        end
    end

    for u = 1, #self.tableHeros do
        for k, v in pairs(m_record_force_list) do
            --tabOwner多队时不显示已在其他队伍中上阵头像框
            if tostring(self.tableHeros[u].partnerId) == tostring(v) then
                table.insert(self.tabOwner, self.tableHeros[u])
                break
            end
        end
    end

    for k, v in pairs(self.tabOwner) do
        if temp_battle_list[tostring(v.partnerId)] then
            v.state = state
        end
    end

    if #m_record_force_list > 0 then
        local sortFun = HeroManager.getSortHeroByType()
        table.sort(self.tabOwner, sortFun);
    end

    self:initFormation()
    self:rendererFormation()
    self:refreshCombinationSkill()
    -- self:setSelfFormationByType(self.curFightType, param)
    -- self:refresh()

    self.dynamicList.numItems = #self.tabOwner
    self.Teamlist.numItems = logicMgr.FormationManager.GetMax()
end

--预设队伍中的英雄已上阵提示
function UIBattleTeam:ShowTeamCommonPop(cb1, cb2)
    local pop = CtrlManager.GetCtrl(PanelNames.UICommonPop)
    pop.Init("79", function(b)
        if b then
            if cb1 then
                cb1()
            end
        else
            if cb2 then
                cb2()
            end
        end
    end)
end
----------------------- 编队 end
----------------------- 神魔上阵 start
function UIBattleTeam:playUpFormationEffect(data)
    local flag = false;
    local isUp = false;
    if data.idx == 6 and data.teamId == 1 then
        if self.lastHelpManId ~= data.modelId then
            flag = true;
        end
        if tonumber(self.lastHelpManId) == 0 or tonumber(self.lastHelpManId) == nil then
            isUp = true;
        end
    else
        if data.teamId == 1 and self.lastFormationPosData[data.idx] == nil or (self.lastFormationPosData[data.idx] and self.lastFormationPosData[data.idx].partnerModelId ~= data.modelId) then
            flag = true;
        end
        if self.lastFormationPosData[data.idx] == nil or (self.lastFormationPosData[data.idx] and self.lastFormationPosData[data.idx].partnerModelId == nil or tonumber(self.lastFormationPosData[data.idx].partnerModelId) == 0) then
            isUp = true;
        end
    end
    if data.teamId == 2 then
        flag = true;
        if data.isEmpty or data.modelId == 0 then
            flag = false;
        end

    end
    if flag and data.modelId and tonumber(data.modelId) > 0 then
        local heroRace = G.dataTable["t_hero"][tostring(data.modelId)]["f_FactionType"];
        local urlFore = nil
        local urlBack = nil

        if heroRace == 1 then
            --上阵的是神
            urlFore = "UIEff/UI_buzhen_shen_fore"
            urlBack = "UIEff/UI_buzhen_shen_back"
        end
        if heroRace == 2 then
            --上阵的是魔
            urlFore = "UIEff/UI_buzhen_mo_fore"
            urlBack = "UIEff/UI_buzhen_mo_back"
        end
        if heroRace == 3 then
            --上阵的是圣山蔷薇
            urlFore = "UIEff/UI_buzhen_qw_fore"
            urlBack = "UIEff/UI_buzhen_qw_back"
        end
        if urlFore then
            if self.upBattleEffectForeObj[data.teamId] == nil then
                self.upBattleEffectForeObj[data.teamId] = {}
            end
            if self.upBattleEffectForeDrawWrapper[data.teamId] == nil then
                self.upBattleEffectForeDrawWrapper[data.teamId] = {};
            end
            if self.upBattleEffectForeAni[data.teamId] == nil then
                self.upBattleEffectForeAni[data.teamId] = {}
            end
            local aniObj = self.upBattleEffectForeObj[data.teamId][data.idx];
            if aniObj and urlFore == aniObj.name then

            else
                resMgr:LoadModelPrefab(urlFore, function(go)
                    local foreNode = self.upBattleShowItemFore[data.teamId][data.idx]
                    local drawWrapper = self.upBattleEffectForeDrawWrapper[data.teamId][data.idx];
                    if (drawWrapper == nil) then
                        drawWrapper = GoWrapper.New();
                        self.upBattleEffectForeDrawWrapper[data.teamId][data.idx] = drawWrapper;
                    end
                    if (aniObj ~= nil) then
                        destroyImmediate(aniObj);
                        aniObj = nil
                    end
                    aniObj = newObject(go);
                    --aniObj:AddComponent(TCanvas);
                    aniObj:AddComponent(TChangeSortingOrder)
                    drawWrapper:SetWrapTarget(aniObj, false)
                    if foreNode then
                        foreNode:SetNativeObject(drawWrapper);
                    else
                        if (aniObj ~= nil) then
                            destroyImmediate(aniObj);
                            aniObj = nil
                        end
                    end

                    --Util.Lua_SetLocalPositionXYZ(self.bossBody.transform, showData.location[1], showData.location[2], 0)
                    Util.Lua_SetLocalScaleXYZ(aniObj.transform, 90, 90, 90)
                    local spineAnim = nil;
                    spineAnim = aniObj:GetComponent("SkeletonAnimation")
                    if isUp then
                        local duration = Util.PlayAction(spineAnim, "idle1", false);
                        utimer.delayCall(function()
                            Util.PlayAction(spineAnim, "idle2", true);
                        end, duration * 1000)
                    else
                        Util.PlayAction(spineAnim, "idle2", true);
                    end
                    self.upBattleEffectForeObj[data.teamId][data.idx] = aniObj;
                    self.upBattleEffectForeAni[data.teamId][data.idx] = spineAnim;
                end);
            end

            if self.upBattleEffectBackObj[data.teamId] == nil then
                self.upBattleEffectBackObj[data.teamId] = {}
            end
            if self.upBattleEffectBackDrawWrapper[data.teamId] == nil then
                self.upBattleEffectBackDrawWrapper[data.teamId] = {};
            end
            if self.upBattleEffectBackAni[data.teamId] == nil then
                self.upBattleEffectBackAni[data.teamId] = {}
            end
            local aniObjB = self.upBattleEffectBackObj[data.teamId][data.idx];
            if aniObj and urlBack == aniObj.name then
            else
                resMgr:LoadModelPrefab(urlBack, function(go)
                    local backNode = self.upBattleShowItemBack[data.teamId][data.idx]
                    local drawWrapper = self.upBattleEffectBackDrawWrapper[data.teamId][data.idx];
                    if (drawWrapper == nil) then
                        drawWrapper = GoWrapper.New();
                        self.upBattleEffectBackDrawWrapper[data.teamId][data.idx] = drawWrapper;
                    end
                    if (aniObjB ~= nil) then
                        destroyImmediate(aniObjB);
                        aniObjB = nil
                    end
                    aniObjB = newObject(go);
                    --aniObj:AddComponent(TCanvas);
                    aniObjB:AddComponent(TChangeSortingOrder)
                    drawWrapper:SetWrapTarget(aniObjB, false)
                    backNode:SetNativeObject(drawWrapper);
                    Util.Lua_SetLocalScaleXYZ(aniObjB.transform, 90, 90, 90)

                    --Util.Lua_SetLocalPositionXYZ(self.bossBody.transform, showData.location[1], showData.location[2], 0)
                    --Util.Lua_SetLocalScaleXYZ(self.bossBody.transform, showData.scale[1], showData.scale[2], 1)
                    local spineAnim = nil;
                    spineAnim = aniObjB:GetComponent("SkeletonAnimation")
                    if isUp then
                        local duration = Util.PlayAction(spineAnim, "idle1", false);
                        utimer.delayCall(function()
                            Util.PlayAction(spineAnim, "idle2", true);
                        end, duration * 1000)
                    else
                        Util.PlayAction(spineAnim, "idle2", true);
                    end
                    self.upBattleEffectBackObj[data.teamId][data.idx] = aniObjB;
                    self.upBattleEffectBackAni[data.teamId][data.idx] = spineAnim;
                end);
            end
        else
            self:clearUpBattleEff(data);
        end
    else
        self:clearUpBattleEff(data);
    end
end

function UIBattleTeam:clearUpBattleEff(data)
    if data.isEmpty then
        if self.upBattleEffectForeObj[data.teamId] and self.upBattleEffectForeObj[data.teamId][data.idx] then
            destroyImmediate(self.upBattleEffectForeObj[data.teamId][data.idx])
            self.upBattleEffectForeObj[data.teamId][data.idx] = nil;
        end
        if self.upBattleEffectBackObj[data.teamId] and self.upBattleEffectBackObj[data.teamId][data.idx] then
            destroyImmediate(self.upBattleEffectBackObj[data.teamId][data.idx])
            self.upBattleEffectBackObj[data.teamId][data.idx] = nil;
        end
    else
        if data.modelId and tonumber(data.modelId) > 0 then
            local heroRace = G.dataTable["t_hero"][tostring(data.modelId)]["f_FactionType"];
            if (heroRace ~= 1 and heroRace ~= 2 and heroRace ~= 3) then
                if self.upBattleEffectForeObj[data.teamId] and self.upBattleEffectForeObj[data.teamId][data.idx] then
                    destroyImmediate(self.upBattleEffectForeObj[data.teamId][data.idx])
                    self.upBattleEffectForeObj[data.teamId][data.idx] = nil;
                end
                if self.upBattleEffectBackObj[data.teamId] and self.upBattleEffectBackObj[data.teamId][data.idx] then
                    destroyImmediate(self.upBattleEffectBackObj[data.teamId][data.idx])
                    self.upBattleEffectBackObj[data.teamId][data.idx] = nil;
                end
            end
        end
    end
end

----------------------- 神魔上阵 end

----------------------- 风暴峡湾相关 start
--- boss积分当前倍率
---@private
function UIBattleTeam:showTrialsPoints()
    local txtPoints = self:GetChild("Text_Point")
    if txtPoints == nil then return end

    local point1 = logicMgr.TrialsManager.getLevelPoint()
    local point2 = logicMgr.TrialsManager.getDurationPoint()
    local point3 = logicMgr.TrialsManager.getBuffPoint()
    local points = point1 * point2 + point3
    txtPoints.text = string.format(getLanguage("UIChaosTestMagnification"), points .. '')
end
--- boss buff列表
---@private
function UIBattleTeam:showTrialsBuff()
    self.trialsBuff = logicMgr.TrialsManager.loadTrialsBuff()
    self.trialsBuffPanel = self:GetChild("ChaosBuff")
    self.ctrlTrialsBuff  = self:GetController("ChaosBuffInfo")
    self:SetDynamicList(self.combinationListEnemy, self.trialsBuffItemRenderer, self, true)

    self.combinationListEnemy.visible  = true
    self.combinationListEnemy.numItems = #self.trialsBuff
    self.combinationListEnemyBgCtrl.selectedIndex = #self.trialsBuff > 0 and 1 or 0

    self:loadTrialsBuffPanel()
end
function UIBattleTeam:loadTrialsBuffPanel()
    if self.trialsBuffPanel == nil then return end
    local list = self.trialsBuffPanel:GetChild("list")
    self:SetDynamicList(list, self.trialsBuffShowItemRenderer, self, true)

    list.numItems = #self.trialsBuff
end
function UIBattleTeam:trialsBuffItemRenderer(index, obj)
    local buffId = self.trialsBuff[index]
    local icon = obj:GetChild("icon")
    local ctrl = obj:GetController("type")
    icon.url  = EnumConst.AtlasPath.SkillAtlas .. buffId
    ctrl.selectedIndex = 1

    obj.onClick:Clear()
    obj.onClick:Add(function() self.ctrlTrialsBuff.selectedIndex = 1 end)
end
function UIBattleTeam:trialsBuffShowItemRenderer(index, obj)
    local buffId = self.trialsBuff[index]
    local cfg  = dataTable.getDataTableByStringId('t_skill', tostring(buffId))
    local icon    = obj:GetChild("n4")
    local txtDesc = obj:GetChild("buffDesc")
    icon.url      = EnumConst.AtlasPath.SkillAtlas .. buffId
    txtDesc.text  = cfg and getLanguage(cfg.f_Desc) or ""
end
----------------------- 风暴峡湾相关 end

return UIBattleTeam